Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / ToolStripMenuItem click event Sets the data source of the grid to null

ToolStripMenuItem click event Sets the data source of the grid to null

New Discussion
Ulises
Ulises asked on Oct 22, 2008 11:05 PM

 

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 !

 

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Oct 21, 2008 9:27 PM

    [quote user="ureyes84"]Clicking on the ToolStripMenuItem
    control will magically set the DataSource of the Grid to null.[/quote] 

    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.

    • 0
      Ulises
      Ulises answered on Oct 21, 2008 9:46 PM

      [quote user="[Infragistics] Mike Saltzman"]  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?[/quote] 

      That's right, that's what is happening.

       [quote user="[Infragistics] Mike Saltzman"]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. [/quote]

      There is an event handler attached to the TooStripMenu click event, only one. which calls the CopySelection method. It is here where I see that the DataSource of the grid is set to null. That's why I mentioned that if I try to re-assign the data source at this point (by calling the BindGridData), I get the null reference exception, which is very interesting because the Grid is not null obviusly and I can see that my object list is not null either, but still it breaks when I assign the object list to the DataSource property of the grid.

       One more thing, the DisplayLayout property is also null.

       I was curious to see if it had to do with using MDI forms. I removed the ToolStripMenu, and added buttons to the grid form, also I added the key shortcuts to these buttons and it now seems to work fine. Same code, nothing changed, except that the event handler responds now to the click of the buttons in the form instead of the click of the  ToolStripMenu, which was in the MDI parent form.

       

      • 0
        Mike Saltzman
        Mike Saltzman answered on Oct 22, 2008 2:22 PM

        Well, my best guess is that when you close the form, something is getting disposed and whatever it is is not getting properly recreated when you re-open the form. But all I can really do is guess.

      • 0
        Ulises
        Ulises answered on Oct 22, 2008 11:05 PM

         Yeah it will be hard to troubleshoot this one.

         

        Thanks for yor help.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Ulises
Favorites
0
Replies
4
Created On
Oct 22, 2008
Last Post
17 years, 5 months ago

Suggested Discussions

Tags

Created by

Created on

Oct 22, 2008 11:05 PM

Last activity on

Feb 19, 2026 3:17 PM