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
1705
ToolStripMenuItem click event Sets the data source of the grid to null
posted

 

Hey guys, 

I have a grid in a form that is contained in a MDI form (the grid form is created by clicking an item of an UltraExplorerBar control), and there are a few ToolStripMenuItem controls in the MDI form that are intended to work as an Edit menu (copy, paste, cut, etc) .

I have added an event handler in the grid form for the click events of the ToolStripMenuItem controls .

The grid seems to work fine, we are able to insert new rows, update, sort, copy, paste, etc, etc.

The problem is when we close the form and create it again (we initialize it by using the form constructor). Clicking on the ToolStripMenuItem control will magically set the DataSource of the Grid to null.

I tried to "fix" it by re-assigning the list of objects to the grid, but I got the following exception in the line Grid.DataSource= ObjList:

 

 "Object reference not set to an instance of an object."

"Infragistics2.Win.UltraWinGrid.v8.2"


   at Infragistics.Win.UltraWinGrid.UltraGridBase.Set_ListManager(Object newDataSource, String newDataMember)
   at Infragistics.Win.UltraWinGrid.UltraGridBase.set_DataSource(Object value)
   at MyProject.DataEntryGrid.SetDataSource() in C:\Documents and Settings\ureyes\My Documents\Visual Studio 2008\Projects\MyProject\UserControls\DataEntryGrid.cs:line 718
   at MyProject.DataEntryGrid.BindGridData() in C:\Documents and Settings\ureyes\My Documents\Visual Studio 2008\Projects\MyProject\UserControls\DataEntryGrid.cs:line 317
   at MyProject.DataEntryGrid.CopySelection(Boolean RemoveSelection) in C:\Documents and Settings\ureyes\My Documents\Visual Studio 2008\Projects\MyProject\UserControls\DataEntryGrid.cs:line 1585
   at MyProject.DataEntryGrid.cutToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Documents and Settings\ureyes\My Documents\Visual Studio 2008\Projects\MyProject\UserControls\DataEntryGrid.cs:line 1572

   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)

 

Any help would be appreciated.

Thanks !

 

Parents
  • 469350
    Verified Answer
    Offline posted

    ureyes84 said:
    Clicking on the ToolStripMenuItem control will magically set the DataSource of the Grid to null.

     

    What exactly do you mean by this?  Are you saying that the code in the ToolStripMenu is NOT setting the data source to null but somehow it's getting set to null, anyway? I'm afraid I have no explanation for that.I don't see how tat could possibly happen. Something in the code must be causing the data source to be set to null if that's what's happening. 

    This call stack is rather interesting. This seems to indicate that your ToolStripMenu is calling a method on your UserControl called CopySelection and it is this method that is calling BindGridData which ultimately ends up causing the null reference exception.

Reply Children