I am new to LINQ, so hopefully this is not a dumb question:
I have a table with a lot of content presented in a datagrid, and I want the user to be able to filter the grid using some combined fields above the grid [for example, the search bar]
I created a method that takes text in a combo box and puts it in a Where clause:
public void find() { string disName; string statusName; disName = RMcmbDis.Text;
// Here I collect all the necessary data
var allCNT = from x in cntDB.releases join dis in cntDB.disciplines on x.discipline equals dis.discipline_id join btch in cntDB.batches on x.batch_num equals btch.batch_id join z in cntDB.status on x.status equals z.status_id select new { dis.discipline_name, x.grade, x.batch_num, btch.batch_name, z.status_description, x.segment_leader, x.ped_leader, x.release_location, x.comments, x.QA_Verdict };
// Here I do the filtering
var find = allCNT.Where(a => a.discipline_name == disName && a.status_description == statusName); dataGridView1.DataSource = find; }
Now I have a problem: I want the user to be able to leave one of the fields with the list empty, and if he does, then he does not want to filter these criteria. [EG - The "RMcmbDis" component has a "Math", and the Status ["RMcmbStatus"] command is empty, so the grid will only show "Math" in all states.
How can I do it? Thanks guys ... N.