updating DataTable using DataGrid
From: JochenZ (JochenZ_at_discussions.microsoft.com)
Date: 09/25/04
- Next message: Kskarthik001: "Re: Executing lengthy query through ADO 2.7"
- Previous message: Val Mazur: "Re: System.Data.DBConcurrencyException"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 25 Sep 2004 02:05:02 -0700
Hello,
I have a DataGrid(View) and a DataTable. The DataTable is displayed in the
DataGridView:
dataGridView.DataSource = theTable;
The user is allowed to select some rows and then the following
snippet updates some values in the selected rows:
foreach (DataGridViewRow row in dataGridView.SelectedRows)
{
row.Cells["theColumnName1"].Value = someCalculatedValue1;
row.Cells["theColumnName2"].Value = someCalculatedValue2;
}
Then the following line of code is executed:
MessageBox.Show(theTable.GetChanges().Rows.Count.ToString());
It turns out that the number of rows returned by GetChanges() is always one
lower than the number of selected rows in the DataGridView. When n rows are
selected, the foreach loop is executed for n rows, n rows change in the
DataGridView, but only n-1 rows are returned by theTable.GetChanges()...
Updating complete rows at once in the DataGridView using row.SetValues(...)
doesn't make a difference. The last selected row, though changed in the
DataGridView, is never actually changed in the DataTable.
I think the changes in the last selected row of the DataGridView are in a
way 'not committed', probably by 'not leaving the row'. So I also tried to
run the foreach loop twice in succession. That would make sure the last
selected row 'had the same treatment' as the others. It didn't help though...
Could anyone help me out please?
Thanks a lot!
Jochen
- Next message: Kskarthik001: "Re: Executing lengthy query through ADO 2.7"
- Previous message: Val Mazur: "Re: System.Data.DBConcurrencyException"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|