views:

360

answers:

1

Say I have a DataGridView Control, this grid is filled through a DataTable. Now, I'd like to add some dynamic filtering, by means of a checkbox. When the _CheckedChanged event is launched and Checked is set to true, I exectue a filter;

DataRow[] rows = grid.Select("foo = bar");

No I want to only show these records in the grid. Now, what I thought was make a new DataTable and make it the datasource to the grid, but I see this getting cumbersome real fast when I have multiple checkboxes. Any pointers or best practices for this one?

+2  A: 

you can use the DefaultView Rowfilter property

((DataTable)dataGridView1.DataSource).DefaultView.RowFilter = "foo = bar";

Have a look at this example

DataTable.DefaultView Property

astander