Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
435
Datarow delete causes error
posted

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

The following error exists in ultrawingrid version 10.2 and 10.3.  It does not exist in version 8.3.

 

We are running into an error that has been hard to pinpoint, but the following source allows you to see a scenario where the error happens every time.  First, in the ultrawingrid InitializeLayout event we set the ExpansionIndicator and LoadStyle.

 

Notice in the btnRemoveChildRecordAndCrash click event a parent record is activated and then a child row is deleted.  The button click event generates the following error when _p1c1.Delete() executes.

Object reference not set to an instance of an object.

 

The  btnRemoveChildRecordWithoutCrashing click event does the exact same thing without activating a row.  Execution is completed without error.

 

If you comment out one or both of the properties set in the InitializeLayout event the error does not occur. 

 

The row activation does not need to be in the button click event.  The error will also occur if it is in the form load or somewhere else. 

 

Please help?

 

Public Class Form1

    Private _dataset As New DataSet

    Private _childTable As New DataTable("ChildTable")

    Private _parentTable As New DataTable("ParentTable")

 

    Private _p1c1 As DataRow

 

    Private WithEvents ugBasicGrid As New Infragistics.Win.UltraWinGrid.UltraGrid

    Private WithEvents btnRemoveChildRecordAndCrash As New Button

    Private WithEvents btnRemoveChildRecordWithoutCrashing As New Button

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.ClientSize = New System.Drawing.Size(662, 404)

 

        Me.ugBasicGrid.Location = New System.Drawing.Point(12, 12)

        Me.ugBasicGrid.Name = "ugBasicGrid"

        Me.ugBasicGrid.Size = New System.Drawing.Size(619, 315)

        Me.Controls.Add(Me.ugBasicGrid)

 

        InitializeDataSet()

        ugBasicGrid.DataSource = _parentTable

 

        Me.btnRemoveChildRecordAndCrash.Text = "Remove Child Record (and crash)"

        Me.btnRemoveChildRecordAndCrash.Location = New System.Drawing.Point(12, 344)

        Me.btnRemoveChildRecordAndCrash.Size = New System.Drawing.Size(184, 23)

        Me.Controls.Add(Me.btnRemoveChildRecordAndCrash)

 

        Me.btnRemoveChildRecordWithoutCrashing.Text = "Remove Child Record (no problem)"

        Me.btnRemoveChildRecordWithoutCrashing.Location = New System.Drawing.Point(200, 344)

        Me.btnRemoveChildRecordWithoutCrashing.Size = New System.Drawing.Size(184, 23)

        Me.Controls.Add(Me.btnRemoveChildRecordWithoutCrashing)

    End Sub

 

    Private Sub InitializeDataSet()

        _dataset.Tables.Add(_parentTable)

 

        _parentTable.Columns.Add(New DataColumn("ParentID", GetType(Integer)))

        _parentTable.Columns.Add(New DataColumn("ParentDescription", GetType(String)))

 

        _parentTable.Rows.Add("1", "parent one")

        _parentTable.Rows.Add("2", "parent two")

 

        _childTable.Columns.Add(New DataColumn("ParentID", GetType(Integer)))

        _childTable.Columns.Add(New DataColumn("ChildID", GetType(String)))

        _childTable.Columns.Add(New DataColumn("ChildDescription", GetType(String)))

 

        _p1c1 = _childTable.Rows.Add("1", "p1c1", "parent one child one")

 

        _dataset.Tables.Add(_childTable)

 

        _dataset.Relations.Add("Relation", _dataset.Tables("ParentTable").Columns("ParentID"), _dataset.Tables("ChildTable").Columns("ParentID"), False)

    End Sub

 

    Private Sub btnRemoveChildRecordAndCrash_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveChildRecordAndCrash.Click

        If _p1c1 Is Nothing Then

            MsgBox("please restart the program before clicking any more buttons.")

            Return

        End If

 

        ugBasicGrid.Rows(1).Activate()

 

        _p1c1.Delete()

        _p1c1 = Nothing

 

        _childTable.AcceptChanges()

 

        MsgBox("Child row removed.")

    End Sub

 

    Private Sub btnRemoveChildRecordWithoutCrashing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveChildRecordWithoutCrashing.Click

        If _p1c1 Is Nothing Then

            MsgBox("please restart the program before clicking any more buttons.")

            Return

        End If

 

        'ugBasicGrid.Rows(1).Activate()

 

        _p1c1.Delete()

        _p1c1 = Nothing

 

        _childTable.AcceptChanges()

 

        MsgBox("Child row removed.")

    End Sub

 

    Private Sub ugBasicGrid_InitializeLayout(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles ugBasicGrid.InitializeLayout

        ugBasicGrid.DisplayLayout.Bands(0).Override.ExpansionIndicator = Infragistics.Win.UltraWinGrid.ShowExpansionIndicator.CheckOnDisplay

        ugBasicGrid.DisplayLayout.LoadStyle = Infragistics.Win.UltraWinGrid.LoadStyle.LoadOnDemand

    End Sub

 

 

End Class