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
40
Modify SelectedRowsCollection throws null exception
posted

I have a SelectionDrag event where I want to examine the SelectedRowsCollection, verify a constraint of the ListObject of each row.  If the ListObject fails the constraint I want to purge it from the SelectedRowsCollection.

 There is no public method on SelectedRowsCollection to remove a row, so I declare another SelectedRowsCollection and attempt to add the valid rows to the alternate collection, and continue the DragDrop with the valid rows.

 However when I add to the SelectedRowsCollection, I get a null reference exception.  Neither the SelectedRowsCollection nor the row is null.  This has to be something from the internal workings of SelectedRowsCollection.Add().  Is this a bug?  It seems like one.  Any Suggestions?

 Here is the code:

             SelectedRowsCollection selectedRows = ((UltraGrid)sender).Selected.Rows;
            SelectedRowsCollection finalRows = new SelectedRowsCollection();

            foreach (UltraGridRow row in selectedRows)
            {
                DomainObject domainObj = (DomainObject) row.ListObject;

                if (NotValid)
                {
                   continue;
                }

                finalRows.Add(row); // Exception is thrown here
            }

            if (finalRows.Count > 0)
            {
                ((UltraGrid)sender).DoDragDrop(finalRows, DragDropEffects.Move);
            }

 

Here is the stack trace

   at Infragistics.Win.UltraWinGrid.SelectedRowsCollection.AddRange(UltraGridRow[ rows, Boolean ensureRowsOrdered, Boolean fireSlectionChangeEvent)
   at Infragistics.Win.UltraWinGrid.SelectedRowsCollection.AddRange(UltraGridRow[ rows)
   at Infragistics.Win.UltraWinGrid.SelectedRowsCollection.Add(UltraGridRow row)
   at MyForm.Grid_SelectionDrag(Object sender, CancelEventArgs e) :line 330
   at Infragistics.Win.UltraWinGrid.UltraGrid.OnSelectionDrag(CancelEventArgs e)
   at Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent(GridEventIds id, EventArgs e)
   at Infragistics.Win.UltraWinGrid.UltraGrid.Infragistics.Win.ISelectionManager.OnDragStart(ISelectableItem item, Point mousePosition)
   at Infragistics.Win.SelectionStrategyBase.DragStart()
   at Infragistics.Win.SelectionStrategyExtended.OnMouseMove(ISelectableItem item, MouseMessageInfo& msginfo)
   at Infragistics.Win.SelectionStrategyExtended.OnMouseMessage(ISelectableItem item, MouseMessageInfo& msginfo)
   at Infragistics.Win.ControlUIElementBase.ProcessMouseMoveHelper(Object sender, MouseEventArgs e)
   at Infragistics.Win.ControlUIElementBase.ProcessMouseMove(Object sender, MouseEventArgs e)
   at System.Windows.Forms.MouseEventHandler.Invoke(Object sender, MouseEventArgs e)
   at System.Windows.Forms.Control.OnMouseMove(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseMove(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Parents Reply Children
No Data