I misunderstood, and didn't realize you were trying to do a filter NOT ON
THE GRID, but on the underlying data source.
So just do the EndEdit and don't do the filter.
The problem is that just because it's typed on the screen, it doesn't mean
it's in the dataset. The BindingSource is the glue between the two, and when
you do EndEdit on the binding source, it no longer has to retain the old and
new values in case the user does an Undo, and it pushes the changed values
down into the data source. At least, that's my take on it from how it
appears to work.
So if you put in the EndEdit on the BS (w/o the filter), does it do what you
are trying to achieve?
RobinS.
GoldMail, Inc.
Hi,
Just tried that (apologies, I thought you meant call EndEdit on the
DataGridView) and yes, DataTable.Select then returns the correct rows.
However, the problem with that is that it filters the underlying data
in the grid! This is not want I want to do, I simply want to analyse
the data. Yes, I could remove the filter on the BindingSource after
I've performed the DataTable.Select but I have very large datasets so
that is not ideal. It will also kick off lots of events throughout my
application.
I still can't understand why simply using a DataTable.Select won't
return the correct rows on the first place? It does when invoked
outside of any of the DataGridView events but I would have thought it
should at least work in OnCellValueChanged i.e. when the grid has the
updated value and the DataTable has the updated value aswell. If the
DataTable hasn't got the updated value at this point in time then why
is the updated value shown in the watch windows for the DataTable?!
Thanks.
Tristan.
Are you doing an EndEdit on the BindingSource to push the new value down
into the dataset? Try doing that before doing the filter.
RobinS.
GoldMail, Inc.
in message
Thanks but I've tried everything you suggest and still have exactly
the same problem! I've also tried using DataViews to do the filtering
but still have the same problem. This leads me to think there is a bug
with the underlying framework unless by design you can't do filtering
inside any of the grid events.
Are you using a binding source? If so, try doing an EndEdit() before
checking the dataset; that pushes the changes from the binding source
down
into the dataset.
If you're not, add one and see if that helps.
myGrid.DataSource = myBindingSource;
myBindingSource.DataSource = myDataSet;
Then do your filter off of the binding source.
myBindingSource.Filter = string.Empty; //remove any current filter
myBindingSource.Filter = ("this column = " + true);
RobinS.
------------------------------------
Hi,
Yes already tried that, also get the same problem with string and
integer columns so nothing to do with it being a boolean column.
Tristan.
Just out of curiosity, have you tried
string filter = "MyBooleanColumn = true";
Assuming your boolean column really IS a boolean, and isn't an int.
RobinS.
---------------------------------------"Tristan"
Hi,
I have a custom DataGridView and the following simple override:
protected override void OnCellValueChanged(DataGridViewCellEventArgs
e)
{
base.OnCellValueChanged(e);
string filter = "MyBooleanColumn = 1";
DataRow[] rows =
((DataTable)this.DataSource).Select(filter);
}
When I inspect the DataTable I can clearly see that it has rows
where
MyBooleanColumn is equal to true. However, the DataTable.Select
operation does not return any rows!
The rows in the table have a RowState of Added and I have tried
passing in all the different row states to no avail.
If I call AcceptChanges it works but I can't do this as I need the
changes to get saved back down to a database.
If I put a button on the form and click it, and in the handler put
in
the same DataTable.Select, it does return the rows (the row states
are
still Added aswell).
Please could someone explain why this strange behaviour is occuring!
Any help appreciated.
Thanks
Tristan.- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -