tags:

views:

474

answers:

3

I have a DataTable that has a boolean column called [Invalid]. I need to divide this data up by this Invalid column - valid rows can be edited, invalid rows cannot. My original plan was to use two BindingSources and set the Filter property ([Invalid] = 'false', for instance), which plays right into my hands because I have two DataGridViews and so I need two BindingSources anyway.

This doesn't work: the BindingSources set the Filter property associated with the DataTable, so both BindingSources hold the same data. Am I going to have to do two fetches from the database, or can I do what I want with the objects I have?

+2  A: 

I don't think you can do it the way you are hoping.

You could use two different dataviews of the same datatable, and bind your datagridviews to those?

deadcat
+1  A: 

When you bind to a DataTable, you are effectively binding to its default view (DataTable.DefaultView). And when you set the Filter property of either BindingSource, you are setting the Filter property of the default view, overwriting the Filter set by the other BindingSource.

So deadcat's answer is correct: you need to bind to two different views on the DataTable (one of which can be the DefaultView if you prefer):

bindingSource1.DataSource = myDataTable;
bindingSource2.DataSource = new DataView(myDataTable);

or

bindingSource1.DataSource = new DataView(myDataTable);
bindingSource2.DataSource = new DataView(myDataTable);
Joe
A: 

The solution to this question was very helpful!

Thanks.

James.

ScrivUK