vb-dev
2022-11-04T14:20:25Z
Greetings,

We occasionally encounter a NullReferenceException when calling iGrid.Sort(). Can someone please tell us if there is anything in our code that appears incorrect?

The Exception is thrown at Line 27, below. I'll update this with more detail the next time I encounter it. Thank you.

        Private Sub LoadData(ByVal searchType As SearchType, ByVal searchString As String, ByVal amount As Decimal)
            Dim moduleName = System.Reflection.MethodBase.GetCurrentMethod.DeclaringType.Name
            Dim message = "Out of memory."

            Try
                Call SearchItemsGrid.BeginUpdate()
                Call GridFunctions.SetGridDefinition(m_DBProcess.DBProcessID, SearchItemsGrid, GridDefinitionDataSet)

                Select Case searchType
                    Case SearchType.AnyText
                        Call SearchItemsGrid.FillWithData(ARCData.ReconArcAccess.SearchItems(SearchType.AnyText, searchString, amount, Globals.User.UserName), True)
                    Case SearchType.ExactMatch
                        Call SearchItemsGrid.FillWithData(ARCData.ReconArcAccess.SearchItems(SearchType.ExactMatch, searchString, amount, Globals.User.UserName), True)
                    Case SearchType.StartsWith
                        Call SearchItemsGrid.FillWithData(ARCData.ReconArcAccess.SearchItems(SearchType.StartsWith, searchString, amount, Globals.User.UserName), True)
                    Case SearchType.EndsWith
                        Call SearchItemsGrid.FillWithData(ARCData.ReconArcAccess.SearchItems(SearchType.EndsWith, searchString, amount, Globals.User.UserName), True)
                    Case SearchType.ExactAmount
                        Call SearchItemsGrid.FillWithData(ARCData.ReconArcAccess.SearchItems(SearchType.ExactAmount, searchString, amount, Globals.User.UserName), True)
                    Case SearchType.ByAmount
                        Call SearchItemsGrid.FillWithData(ARCData.ReconArcAccess.SearchItems(SearchType.ByAmount, searchString, amount, Globals.User.UserName), True)
                End Select

                Call RestoreGridLayout(SearchItemsGrid)
                Call SearchItemsGrid.SortObject.Clear()
                Call SearchItemsGrid.SortObject.Add(SearchItemsGrid.Cols("AMOUNT").Index, iGSortOrder.Descending)
                Call SearchItemsGrid.Sort()  '<-- NullReferenceException is intermittently thrown here.
                Call SearchItemsGrid.EndUpdate()

                LineItemsTextBox.Text = Convert.ToString(SearchItemsGrid.Rows.Count)
            Catch ex As OutOfMemoryException
                ExceptionManager.HandleException(ex, moduleName, ExceptionScope.Handled, message)
            End Try
        End Sub
Igor/10Tec
2022-11-04T14:37:22Z
It's impossible to guess what can be wrong just looking at this code. Most likely, the problem is related to your data. It would be nice if you could reproduce the problem in a brand new project and send it to us for the further consideration. In any case, if you can provide more details, update this thread.
vb-dev
2022-11-04T16:08:40Z
Thank you, Igor. Since it is intermittent we are mainly interested at this point whether or not the basic sequence is a problem (clear the SortObject, add a SortObject, then call .Sort). Apparently it is not a problem, so the next time I encounter it I'll try to study the matter closely and determine what exactly is Null.

And, yes, if we can figure out the conditions that cause this and so make it repeatable, we will send a new project. Thanks again.

vb-dev
2023-02-02T17:44:47Z
Igor, we still get this Exception. I did not previously have a stack trace - one was sent to me by a user. Can you spot anything helpful in it?

I have not yet been able to reproduce the issue. When I am, I will attempt to reproduce it in a new project and send it. Thank you.

Exception Source: TenTec.Windows.iGridLib.iGrid.v10.0
Exception Type: System.NullReferenceException
Exception Message: Object reference not set to an instance of an object.
Exception Target Site: GetRowFromY

---- Stack Trace ----
TenTec.Windows.iGridLib.iGrid.GetRowFromY(y As Int32, rowIndex As Int32&, rowY As Int32&, rowHeight As Int32&)
ARCNet_UAT.exe: N 00162
TenTec.Windows.iGridLib.iGrid.GetCellFromPointInternal(x As Int32, y As Int32, includeLevel As Boolean, rowIndex As Int32&, colOrder As Int32&, bounds As Rectangle&)
ARCNet_UAT.exe: N 00078
TenTec.Windows.iGridLib.iGrid.ProcessCellsMouseMove(x As Int32, y As Int32, button As MouseButtons)
ARCNet_UAT.exe: N 00081
TenTec.Windows.iGridLib.iGrid.ProcessMouseMove(x As Int32, y As Int32, button As MouseButtons)
ARCNet_UAT.exe: N 00592
TenTec.Windows.iGridLib.iGrid.ProcessMouseMove()
ARCNet_UAT.exe: N 00164
TenTec.Windows.iGridLib.iGrid.SortInternal()
ARCNet_UAT.exe: N 00086
TenTec.Windows.iGridLib.iGrid.Sort()
ARCNet_UAT.exe: N 00019
ARCNet.SubLedger.OpenItemsForm.LoadOpenItemsGrid()
ARCNet_UAT.exe: N 00537
ARCNet.SubLedger.OpenItemsForm.LoadAccountKey(permission As UserPermission)
ARCNet_UAT.exe: N 00292
ARCNet.SubLedger.OpenItemsForm.LoadSelectedAccount()
ARCNet_UAT.exe: N 01788
ARCNet.SubLedger.OpenItemsForm.AccountsComboBox_SelectionChangeCommitted(sender As Object, e As ValueChangedEventArgs`1)
ARCNet_UAT.exe: N 00034
ARCControls.IGridComboBox.HostedControl_CellMouseUp(sender As Object, e As iGCellMouseUpEventArgs)
ARCNet_UAT.exe: N 00281
TenTec.Windows.iGridLib.iGrid.OnCellMouseUp(e As iGCellMouseUpEventArgs)
ARCNet_UAT.exe: N 00023
TenTec.Windows.iGridLib.iGrid.DoCellMouseUp(button As MouseButtons, modifierKeys As Keys)
ARCNet_UAT.exe: N 00194
TenTec.Windows.iGridLib.iGrid.ProcessCellsMouseUp(x As Int32, y As Int32, button As MouseButtons)
ARCNet_UAT.exe: N 00125
TenTec.Windows.iGridLib.iGrid.ProcessMouseUp(x As Int32, y As Int32, button As MouseButtons)
ARCNet_UAT.exe: N 00277
TenTec.Windows.iGridLib.iGrid.OnMouseUp(e As MouseEventArgs)
ARCNet_UAT.exe: N 00025
System.Windows.Forms.Control.WmMouseUp(m As Message&, button As MouseButtons, clicks As Int32)
ARCNet_UAT.exe: N 00645
System.Windows.Forms.Control.WndProc(m As Message&)
ARCNet_UAT.exe: N 11013804
TenTec.Windows.iGridLib.iGrid.WndProc(m As Message&)
ARCNet_UAT.exe: N 00611
System.Windows.Forms.ControlNativeWindow.OnMessage(m As Message&)
ARCNet_UAT.exe: N 00018
System.Windows.Forms.ControlNativeWindow.WndProc(m As Message&)
ARCNet_UAT.exe: N 00052
System.Windows.Forms.NativeWindow.Callback(hWnd As IntPtr, msg As Int32, wparam As IntPtr, lparam As IntPtr)
ARCNet_UAT.exe: N 00127
Igor/10Tec
2023-02-03T15:47:05Z
I definitely need a project I can launch on my dev pc to investigate this problem.

The stack trace you published shows interesting things. I see you host another control inside the 'problem' iGrid, then sort this iGrid when something changes in the hosted control. Your construction may cause a conflict that leads to the exception.