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?
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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With