DataGrid: Update data source when editing a cell and closing the f

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

Guest

Hi,

Suppose there is a DataGrid on a form bound to a DataTable. When a user is
editing a cell without leaving the cell, and then closes the form, the value
is not updated to the underlying data source.

How can I accomplish this?

Thanks,
 
CurrencyManager cm =
(CurrencyManager)this.BindingContext[dataGrid.DataSource,
dataGrid.DataMember];
cm.EndCurrentEdit();
DataGridColumnStyle curColumn =
dataGrid.TableStyles[0].GridColumnStyles[dataGrid.CurrentCell.ColumnNumber];
dataGrid.EndEdit(curColumn, dataGrid.CurrentRowIndex, false);
 
It doesn't work. EndEdit *always* returns false, even if the entry is valid.

Unbelievable that even such trivial operations are so hard to find, and when
you try them they don't even work.

Duh,
Tom T.

Dmytro Lapshyn said:
CurrencyManager cm =
(CurrencyManager)this.BindingContext[dataGrid.DataSource,
dataGrid.DataMember];
cm.EndCurrentEdit();
DataGridColumnStyle curColumn =
dataGrid.TableStyles[0].GridColumnStyles[dataGrid.CurrentCell.ColumnNumber];
dataGrid.EndEdit(curColumn, dataGrid.CurrentRowIndex, false);

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


TT (Tom Tempelaere) said:
Hi,

Suppose there is a DataGrid on a form bound to a DataTable. When a user is
editing a cell without leaving the cell, and then closes the form, the
value
is not updated to the underlying data source.

How can I accomplish this?

Thanks,
 
Try to swap the order - call EndEdit first and then EndCurrentEdit on the
CurrencyManager.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


TT (Tom Tempelaere) said:
It doesn't work. EndEdit *always* returns false, even if the entry is
valid.

Unbelievable that even such trivial operations are so hard to find, and
when
you try them they don't even work.

Duh,
Tom T.

Dmytro Lapshyn said:
CurrencyManager cm =
(CurrencyManager)this.BindingContext[dataGrid.DataSource,
dataGrid.DataMember];
cm.EndCurrentEdit();
DataGridColumnStyle curColumn =
dataGrid.TableStyles[0].GridColumnStyles[dataGrid.CurrentCell.ColumnNumber];
dataGrid.EndEdit(curColumn, dataGrid.CurrentRowIndex, false);

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message
Hi,

Suppose there is a DataGrid on a form bound to a DataTable. When a user
is
editing a cell without leaving the cell, and then closes the form, the
value
is not updated to the underlying data source.

How can I accomplish this?

Thanks,
 
Dmytro,

Thanks for the suggestion. I'll try it out.

Thank you,
Tom T.
PS: Sorry for the frustrated tone ;-), DataGrid is rather complex sometimes.

Dmytro Lapshyn said:
Try to swap the order - call EndEdit first and then EndCurrentEdit on the
CurrencyManager.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message
It doesn't work. EndEdit *always* returns false, even if the entry is
valid.

Unbelievable that even such trivial operations are so hard to find, and
when
you try them they don't even work.

Duh,
Tom T.

Dmytro Lapshyn said:
CurrencyManager cm =
(CurrencyManager)this.BindingContext[dataGrid.DataSource,
dataGrid.DataMember];
cm.EndCurrentEdit();
DataGridColumnStyle curColumn =
dataGrid.TableStyles[0].GridColumnStyles[dataGrid.CurrentCell.ColumnNumber];
dataGrid.EndEdit(curColumn, dataGrid.CurrentRowIndex, false);

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


"TT (Tom Tempelaere)"
<_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message
Hi,

Suppose there is a DataGrid on a form bound to a DataTable. When a
user is
editing a cell without leaving the cell, and then closes the form, the
value
is not updated to the underlying data source.

How can I accomplish this?

Thanks,
 
Back
Top