Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGrid.RowState lost...
 

DataGrid.RowState lost...

I have a problem where my DataGrid is "forgetting" the implicit setting of it's RowState property to Modified. for example if I alter 3 rows in the grid and change the property to modified, it will only remember the last row altered, it will not remember that the 1st 2 have also been set to modified.

I have tried multiple flavours of the block of code below to try and force the grid to remember the RowState, but to no avail... Does anyone have any idea?

[code="vb"]
CType(Me.grdMeasures.BindingContext(Me.grdMeasures.DataSource, Me.grdMeasures.DataMember).Current, DataRowView).BeginEdit()
CType(Me.grdMeasures.BindingContext(Me.grdMeasures.DataSource, Me.grdMeasures.DataMember).Current, DataRowView)(TblMeasureDataEntry.MEASURE_MIN_BAND) = record.measureBandMinimum
CType(Me.grdMeasures.BindingContext(Me.grdMeasures.DataSource, Me.grdMeasures.DataMember).Current, DataRowView)(TblMeasureDataEntry.MEASURE_MAX_BAND) = record.measureBandMaximum
CType(Me.grdMeasures.BindingContext(Me.grdMeasures.DataSource, Me.grdMeasures.DataMember).Current, DataRowView).EndEdit()
row.SetModified()

Thanks a million
[/code]
Hena  Tuesday, March 20, 2007 10:08 AM

"RowState" or "SetModified" are members of DataRow, instead of DataGrid.

Apparently the following codewill always workas expected:

DataTable dt = new DataTable();
dt.Columns.Add("Column1", typeof(string));
dt.Columns.Add("Column2", typeof(string));
for (int i = 0; i < 1000; i++) {
dt.Rows.Add("Test row " + i.ToString(), "Column2 value");
}
dt.AcceptChanges();
dt.Rows[0].SetModified();
dt.Rows[200].SetModified();
dt.Rows[50].SetModified();
DataTable dtChanged = dt.GetChanges(DataRowState.Modified);
MessageBox.Show(dtChanged.Rows.Count.ToString());

So if you want to track this further, you can simplify your code further and paste it here, specially on how you determine only the last altered row state is remembered.

Ting Wang  Friday, March 23, 2007 3:24 AM

"RowState" or "SetModified" are members of DataRow, instead of DataGrid.

Apparently the following codewill always workas expected:

DataTable dt = new DataTable();
dt.Columns.Add("Column1", typeof(string));
dt.Columns.Add("Column2", typeof(string));
for (int i = 0; i < 1000; i++) {
dt.Rows.Add("Test row " + i.ToString(), "Column2 value");
}
dt.AcceptChanges();
dt.Rows[0].SetModified();
dt.Rows[200].SetModified();
dt.Rows[50].SetModified();
DataTable dtChanged = dt.GetChanges(DataRowState.Modified);
MessageBox.Show(dtChanged.Rows.Count.ToString());

So if you want to track this further, you can simplify your code further and paste it here, specially on how you determine only the last altered row state is remembered.

Ting Wang  Friday, March 23, 2007 3:24 AM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView and DataGridViewComboBoxColumn
• Saving data drom a Combobox
• Adding,updating and deleting rows on a datagridview
• DataGridView + ComboBox Error leaving cell - I'm stuck!
• Need Help.. plsss
• List Object-->BindingSource = But BindingNavigator wont work
• Datatable column to array
• Refresh GridView with the updated datasource autmatically without loading the form
• Column Expressions not accepting static methods?
• Last Editted Cell Position & Datagrid cell value