Rick D
Rick D

Reputation: 139

Display results based on checkbox selection

I'm trying to query a DataGridView based on a search term and further refine the result based on CheckBox status. I have the following code

var memberIdSearch =    from m in context.Members
                        where m.MemberId == idSearch
                        where checkBoxActive.Checked && m.MemberStatus == "Active"
                        where checkBoxInactive.Checked && m.MemberStatus == "Inactive"
                        select m;

When querying, no matter the search term I enter, no results are returned regardless of CheckBox status. If i comment out the checkbox lines, the query returns all entries matching the search term

What I'm trying to achieve

If memberid matches search term, if active checkbox is ticked, display all display all active members, and if inactive checkbox is ticked, also display inactive members

I'm sure this is something simple, but I can't work it out

Upvotes: 1

Views: 80

Answers (1)

iceberg
iceberg

Reputation: 596

Try to group all statements in one:

var memberIdSearch =    from m in context.Members
                        where m.MemberId == idSearch && 
                        (checkBoxActive.Checked && m.MemberStatus == "Active" ||
                         checkBoxInactive.Checked && m.MemberStatus == "Inactive")
                        select m;

Upvotes: 1

Related Questions