W
WineNCheese
I have a mouse up event handler for a bound DataGrid with a bunch of
bool checkboxes. I want to update the data source as the user checks
(there is no submit button). The code to do so is below, and it works
fine, except the last change is not committed until the next change is
made (kind of like it is not flushed). The last change I make before
quitting the app is never persisted.
I've tried the BindingManager.EndCurrentEdit() with no success.
Any pointers appreciated...
private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Point pt = dataGrid1.PointToClient(Control.MousePosition);
DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
if( hti.Type == DataGrid.HitTestType.Cell && hti.Column>=1 &&
hti.Column<=5 )
{
// Set the value in the control
this.dataGrid1[hti.Row, hti.Column] = ! (bool)(dataGrid1[hti.Row,
hti.Column]);
// This does nothing...
BindingManagerBase bm = this.dataGrid1.BindingContext[
this.testDataSet1, "TestTable" ];
bm.EndCurrentEdit();
// Update the database.
this.sqlDataAdapter1.Update( this.testDataSet1 );
}
}
bool checkboxes. I want to update the data source as the user checks
(there is no submit button). The code to do so is below, and it works
fine, except the last change is not committed until the next change is
made (kind of like it is not flushed). The last change I make before
quitting the app is never persisted.
I've tried the BindingManager.EndCurrentEdit() with no success.
Any pointers appreciated...
private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Point pt = dataGrid1.PointToClient(Control.MousePosition);
DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
if( hti.Type == DataGrid.HitTestType.Cell && hti.Column>=1 &&
hti.Column<=5 )
{
// Set the value in the control
this.dataGrid1[hti.Row, hti.Column] = ! (bool)(dataGrid1[hti.Row,
hti.Column]);
// This does nothing...
BindingManagerBase bm = this.dataGrid1.BindingContext[
this.testDataSet1, "TestTable" ];
bm.EndCurrentEdit();
// Update the database.
this.sqlDataAdapter1.Update( this.testDataSet1 );
}
}