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."

                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
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.
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.