Home Forums WinForms controls Xceed Grid for WinForms exception when removing selected column with no rows Reply To: exception when removing selected column with no rows

User (Old forums)
Post count: 23064

This may be related to an error I had recently. When a row is in edit mode, and I call the DataRows.Clear method, I get a System.InvalidOperationException with the message:

“An attempt was made to set the value of a cell that is not yet associated with a grid.”

The call stack looks like:

at Xceed.Grid.DataCell.SetCurrentValue(Object value)
at Xceed.Grid.DataCell.SetValue(Object value)
at Xceed.Grid.Cell.InternalSetValue(Object value)
at Xceed.Grid.CellRow.CancelEditCore(ArrayList cellChangedIndex)
at Xceed.Grid.DataRow.CancelEditCore(ArrayList cellChangedIndex)
at Xceed.Grid.CellRow.CancelEdit()
at Xceed.Grid.DetailGrid.ClearGridBody()
at Xceed.Grid.DetailGrid.DataManager_DataRowsChanged(Object sender, DataRowsChangedEventArgs e)
at Xceed.Grid.DataManager.OnDataRowsChanged(DataRowsChangedEventArgs e)
at Xceed.Grid.DataManager.InvokeOnDataRowsChanged(DataRowsChangedEventArgs e)
at Xceed.Grid.Collections.DataRowList.OnClearComplete()
at Xceed.Utils.Collections.ListBase.InternalClear()
at Xceed.Utils.Collections.ListBase.ListClear()
at Xceed.Grid.Collections.DataRowList.Clear()

This certainly looks like a bug in the grid to me. The workaround I found was to call the CancelEdit method before the DataRows.Clear method:

if (null != grid.CurrentRow)
Xceed.Grid.CellRow r = grid.CurrentRow as Xceed.Grid.CellRow;
if(null != r) r.CancelEdit();

Imported from legacy forums. Posted by Richard (had 3314 views)