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

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,
 
D

Dmytro Lapshyn [MVP]

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);
 
G

Guest

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,
 
D

Dmytro Lapshyn [MVP]

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,
 
T

TT \(Tom Tempelaere\)

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top