How to programmatically post proposed values for a row in windows form datagrid?

  • Thread starter Thread starter XIA Chengbin
  • Start date Start date
X

XIA Chengbin

Hello!

Would anyone kindly teach me how to programmatically post proposed values
for a row in windows form
datagrid?

The reason that I raise this question is -- whenever I call
OdbcDataAdpter.Update() method to apply updates and inserts the user
performed on a
datagrid, I would always lose the modifications on the row that is last
edited. I have to ask my users to manually click another row to post all
proposed values to the dataset.

By the way, this code fails to be effective:

this.BindingContex[mydataset.mytable].EndCurrentEdit(); //this = the
form

(My datagrid is bound to "mydataset.mytable", so I'm NOT using the wrong
CurrencyManager.)


TIA,
XIA Chengbin
 
I had a similar problem. I added a little extra code than what you have...

===== CODE =======================================================
private void FocusChange()
{
if (grdSplits.DataSource != null)
{
grdSplits.EndEdit(null, grdSplits.CurrentRowIndex, false);
grdSplits.BindingContext[grdSplits.DataSource,
grdSplits.DataMember].EndCurrentEdit();
grdSplits.Invalidate();
grdSplits.Update();
}
}
private void grdSplits_Leave(object sender, System.EventArgs e)
{
FocusChange();
}
private void grdSplits_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
FocusChange();
}
===== End CODE ====================================================

I think the Invalidate and Update helps. Also make sure you call it on the
grid focus related events as shown.

You can get all of the DataTable's changed records via...

DataTable dtChanges = mydataset.mytable.GetChanges();

You could then bind that table to another grid. You could have both grids
on the same form if you want. Then add to the FocusChange() method the
binding of "dtChanges" to the 2nd grid. Now the user can see the changes
that would be committed as they are making the changes.

Michael Lang
 
Back
Top