Object Reference not set on DataSet value change?

  • Thread starter Thread starter Stephen Boutros
  • Start date Start date
S

Stephen Boutros

I've just installed the .NET Framework 1.1 SP1 and suddenly things that used
to work are giving me problems. Specifically, I have a grid (not an MS
DataGrid but one from a third-party) which is bound to a DataView. One of
the columns is boolean and the grid displays checkboxes, as expected. When
the user clicks on a checkbox, thereby updating the underlying data, I get
an error message from the grid: Object Reference not set to an instance of
an object. No more information than that; not very useful.

Knowing that the grid was wrapping the real exception with one of its own, I
tried to update the data "manually", i.e. as if nothing was bound to the
data view. I figured out that if I force the value of the cell in the
CellEdited even fired by this grid before the update is final, I get the
same error. Here is my line of code and the full error message:

myDataSet.myTable.Rows(rownumber).Item("MyColumn") = True

And I get:
Object reference not set to an instance of an object.
at System.Data.DataTable.RecordStateChanged(Int32 record1,
DataViewRowState oldState1, DataViewRowState newState1, Int32 record2,
DataViewRowState oldState2, DataViewRowState newState2)
at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord,
DataRowAction action, Boolean isInMerge)
at System.Data.DataRow.SetNewRecord(Int32 record)
at System.Data.DataRow.EndEdit()
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRow.set_Item(String columnName, Object value)
at MyForm.MyGrid_CellEdited(Object sender, ColumnActionEventArgs e) in
myform.vb:line 3016


Just to be clear: this problem did not occur before the installation of SP1.
I've searched the Microsoft KB and found the following two articles,
downloaded the hotfixes, but they did not help:

http://support.microsoft.com/?kbid=889531
and
http://support.microsoft.com/?kbid=887549

I'm starting to run out of ideas. Somebody out there with a lead? Any help
or inspiration is appreciated at this point.

Thanks,
Steph

P.S.: watch out for the email address when replying personally.
 
I found the apparent source of the problem. But first, more context: the
items listed in my grid are to be selected by the user (thus the checkbox
column). However, the user must also specify a "default" item. To do that, a
combobox is loaded with the list of selected items and one of them is
selected by the user as the default value. In order to do this, both the
combobox uses a datasource equal to a dataview filtering on the original
dataset (filter="selected=1"). The dataset itself has four columns: an ID,
Selected, Default, and the Name of the item. When the user selected a value
in the combobox, the SelectedIndexChanged event was fired, the current
Default row of the dataset was reset to 0 and the new selected value was
updated with a Default=1.

Now with SP1, when a value is selected on the grid, a SelectedIndexChanged
event is fired. This causes the row which is the Default row to be reset to
0 then to 1 again (since the selection actually hasn't changed). When that's
done, apparently before the CellEdited event is finished, the DataSet is
somehow lost and the grid can no longer update the selection.

Now, in pre-SP1, the event may have also fired (I'd have to re-install a
fresh non-SP1 machine just to check), but it certainly did not cause the
DataSet to lost its row (or the Grid to lose the DataSet row, whichever the
case may be).

Bottom line: don't change data in your dataset while you're in an event
which is also trying to update it. In my case, that meant getting rid of the
code in the SelectedIndexChange event and deal with the update of the
Default flag later (which is more efficient anyway since I'll only do it one
instead of at each selection click).

Hope this helps someone....

Steph
 
Back
Top