DataGrid row: RowState unchange problem
-
Hi, I created a datagrid, bonding with a datatable, with some columns editable. If edit the fields in one row, and cursor stays in the same row,RowState is still "Unchanged", although the datatable has the new value now. RowState will be "Modified" only when I move the cursor to another row. But I want to save my changes to database without moving the cursors to other rows. How should I do it? BTW, I use : "if (r.RowState != DataRowState.Unchanged && r.RowState != DataRowState.Deleted)" to judge whether there are changes need to be saved. I don't want to remove this condition because it will cause a lot of unnecessary updates. Thanks.
-
Hi, I created a datagrid, bonding with a datatable, with some columns editable. If edit the fields in one row, and cursor stays in the same row,RowState is still "Unchanged", although the datatable has the new value now. RowState will be "Modified" only when I move the cursor to another row. But I want to save my changes to database without moving the cursors to other rows. How should I do it? BTW, I use : "if (r.RowState != DataRowState.Unchanged && r.RowState != DataRowState.Deleted)" to judge whether there are changes need to be saved. I don't want to remove this condition because it will cause a lot of unnecessary updates. Thanks.
Get the
CurrencyManager
for theDataGrid
and callEndCurrentEdit
like so:CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember];
if (cm != null)
cm.EndCurrentEdit();Also, use
DataSet.GetChanges
orDataTable.GetChanges
and get theCount
of rows for the tables. This is a better way of determining changes plus gives you aDataSet
of just the changes so that you can pass that to your methods which update the data source (i.e., database). This will also be more efficient if you need to send thisDataSet
across application boundaries since it won't (potentially) require as much bandwidth since it would have fewer rows.Microsoft MVP, Visual C# My Articles
-
Get the
CurrencyManager
for theDataGrid
and callEndCurrentEdit
like so:CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember];
if (cm != null)
cm.EndCurrentEdit();Also, use
DataSet.GetChanges
orDataTable.GetChanges
and get theCount
of rows for the tables. This is a better way of determining changes plus gives you aDataSet
of just the changes so that you can pass that to your methods which update the data source (i.e., database). This will also be more efficient if you need to send thisDataSet
across application boundaries since it won't (potentially) require as much bandwidth since it would have fewer rows.Microsoft MVP, Visual C# My Articles