DataGrid Changes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When a DataGrid control is edited, the last cell edited will not be saved to
the associated DataSet as a change until the user changes focus to a
different cell in the grid using the arrow keys, enter, or the mouse. I have
a button in my windows form that needs to save the changes to the DataSet
using a DataAdapter and I would like it to include the cell which is
currently being edited. I tried using EndEdit on the current cell, but it
generated the same behavior, still not saving the data. I also tried adding
a hidden control and changing the focus from the DataGrid. Any other ideas?

Thanks in advance,
Greg Bayard
 
Hi,

Get the current underlying row being pointed to using the Binding Context.
Eg:
DataRow dRow =
((DataRowView)(this.BindingContext[datatablename].Current)).Row;

Then call EndEdit on it.
Eg:
dRow.EndEdit();

Is this what you are doing @ present?

HTH,
Rakesh Rajan
 
Currently I am calling the DataGrid's EndEdit method, I will try this instead
and let you know if it works.

Thanks,
Greg Bayard

Rakesh Rajan said:
Hi,

Get the current underlying row being pointed to using the Binding Context.
Eg:
DataRow dRow =
((DataRowView)(this.BindingContext[datatablename].Current)).Row;

Then call EndEdit on it.
Eg:
dRow.EndEdit();

Is this what you are doing @ present?

HTH,
Rakesh Rajan

GBayard said:
When a DataGrid control is edited, the last cell edited will not be saved to
the associated DataSet as a change until the user changes focus to a
different cell in the grid using the arrow keys, enter, or the mouse. I have
a button in my windows form that needs to save the changes to the DataSet
using a DataAdapter and I would like it to include the cell which is
currently being edited. I tried using EndEdit on the current cell, but it
generated the same behavior, still not saving the data. I also tried adding
a hidden control and changing the focus from the DataGrid. Any other ideas?

Thanks in advance,
Greg Bayard
 
Hmm, doens't work. I get a cast exception, not getting a DataRowView type.

Here's the code:

DataSet catalogData;
DataGrid catalogGrid;

DataRow dRow =
((DataRowView)(this.BindingContext[catalogGrid].Current)).Row;

dRow.EndEdit();

Not very experienced with the Binding Context and Binding Manager so i don't
know how to get to the DataRowView...

Any ideas?

Thanks,
Greg


GBayard said:
Currently I am calling the DataGrid's EndEdit method, I will try this instead
and let you know if it works.

Thanks,
Greg Bayard

Rakesh Rajan said:
Hi,

Get the current underlying row being pointed to using the Binding Context.
Eg:
DataRow dRow =
((DataRowView)(this.BindingContext[datatablename].Current)).Row;

Then call EndEdit on it.
Eg:
dRow.EndEdit();

Is this what you are doing @ present?

HTH,
Rakesh Rajan

GBayard said:
When a DataGrid control is edited, the last cell edited will not be saved to
the associated DataSet as a change until the user changes focus to a
different cell in the grid using the arrow keys, enter, or the mouse. I have
a button in my windows form that needs to save the changes to the DataSet
using a DataAdapter and I would like it to include the cell which is
currently being edited. I tried using EndEdit on the current cell, but it
generated the same behavior, still not saving the data. I also tried adding
a hidden control and changing the focus from the DataGrid. Any other ideas?

Thanks in advance,
Greg Bayard
 
My bad, I figured out the type exception. Here's the code broken apart for
readability:

DataRowView dRowView =
(DataRowView)this.BindingContext[catalogData.Tables["Parts"]].Current;

DataRow dRow = dRowView.Row;

dRow.EndEdit();

So that works fine, but it does not save the current state of the cell
currently being edited, it reverts back to the original cell value. This is
a tough one like my other attempts.

Thanks,
Greg

Rakesh Rajan said:
Hi,

Get the current underlying row being pointed to using the Binding Context.
Eg:
DataRow dRow =
((DataRowView)(this.BindingContext[datatablename].Current)).Row;

Then call EndEdit on it.
Eg:
dRow.EndEdit();

Is this what you are doing @ present?

HTH,
Rakesh Rajan

GBayard said:
When a DataGrid control is edited, the last cell edited will not be saved to
the associated DataSet as a change until the user changes focus to a
different cell in the grid using the arrow keys, enter, or the mouse. I have
a button in my windows form that needs to save the changes to the DataSet
using a DataAdapter and I would like it to include the cell which is
currently being edited. I tried using EndEdit on the current cell, but it
generated the same behavior, still not saving the data. I also tried adding
a hidden control and changing the focus from the DataGrid. Any other ideas?

Thanks in advance,
Greg Bayard
 
Back
Top