473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dynamic MenuItems *weird* problem



Hi. I'M having a weird problem with addign menuitems to a menu dynamically
on the popup event of the menuitem containing the container of the
menuitems i wanna add (tools -> external -> {list of items dynamically
added})

All the code works #1 when only the MdiParent form is used, as soon as i
open an MdiChild in it, right after the popup event returns, i get this
error:

================================================== =======================
A first chance exception of type 'System.NullReferenceException' occurred
in system.windows.forms.dll

Additional information: Object reference not set to an instance of an
object.

An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll

Additional information: Object reference not set to an instance of an
object.
Unhandled Exception: System.NullReferenceException: Object reference not
set to an instance of an object.
at System.Windows.Forms.MenuItem.UpdateMenuItemIfDirt y()
at System.Windows.Forms.MenuItem.OnPopup(EventArgs e)
at System.Windows.Forms.MenuItem.OnInitMenuPopup(Even tArgs e)
at System.Windows.Forms.MenuItem._OnInitMenuPopup(Eve ntArgs e)
at System.Windows.Forms.Menu.ProcessInitMenuPopup(Int Ptr handle)
at System.Windows.Forms.Form.WmInitMenuPopup(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DefFrameP roc(IntPtr hWnd,
IntPtr hWndClient, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmSysCommand(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DefFrameP roc(IntPtr hWnd,
IntPtr hWndClient, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmNcButtonDown(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMeth
ods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32
reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at MoHScriptEdit.frmMain.Main() in d:\my documents\visual studio
projects\medal of honor editor\frmmain.cs:line 518The program '[340]
MoHScriptEdit.exe' has exited with code 0 (0x0).

================================================== =======================

Here is the code i use to add the items, i repeat, it works fine when only
the MdiParent is opened. And the MdiChild DON'T have a "Tools" menu.

private void mnuTools_Popup(object sender, EventArgs e)
{
Debug.WriteLine("Enter frmMain.mnuTools_Popup()");
PopulateExternalToolsMenu();
Debug.WriteLine("Exit frmMain.mnuTools_Popup()");
}

private void PopulateExternalToolsMenu()
{
Debug.WriteLine("Enter frmMain.PopulateExternalToolsMenu()");
mnuExternalTools.MenuItems.Clear();

if(settings.Tools.Count > 0)
{
Debug.WriteLine("Tools Count:" + settings.Tools.Count);

foreach(ExternalTool tool in settings.Tools)
{
Debug.WriteLine("Tool:" + tool.toolName);
MenuItem mi = new MenuItem();
mi.Text = tool.toolName;

mnuExternalTools.MenuItems.Add(mi);

Debug.WriteLine("\t -> Added. Count is now " +
mnuExternalTools.MenuItems.Count);
}
}
Debug.WriteLine("Exit frmMain.PopulateExternalToolsMenu()");
}

I'm really lost, it's very basic simple code and even using step by step i
can't find what generates the error. I also tried adding items directly
through mnuExternalTools.MenuItems.Add("Item Text") but it gives the same
error.

Any clue on what it can be?

--
Deutsche Dogge
www.doggesoft.com
Jul 21 '05 #1
0 1327

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eddie de Bear | last post by:
Hi, A project I am working on has a requirement for dynamic menus. For the most part this works really well. The menus I'm creating a based on files and directories, so naturally the menu...
0
by: Dan H | last post by:
I'm trying to add menu items dynamically in the Popup event of a MenuItem in an MDI child form. Actually, I'm using the Genghis MRU class, but have also dumbed it down to a simple test case in a...
1
by: Martin Falta | last post by:
Hi all, I need a help with following problem. I need to create a menu from dynamic loaded assembly on the main form of my application. The menu is created succesfully, but the events of this...
6
by: Ed Sutton | last post by:
I am dynamically appending to a context menu when user right mouse clicks on a treeView. The first time I right-mouse click I see the appended menu. Subsequently, the menu items I append do not...
4
by: Matthew Speed | last post by:
I am developing an MDI database access app that will be used by people with varying access rights. Is it possible to make menu items show or be hidden based upon the authority of the user? ...
0
by: Peter Osawa | last post by:
Hi, I'm trying to make a dynamic menu loading menuitems from a db. I managed to do this: Dim mnuPrincipal As New MainMenu For intContador = 0 To 5 Dim mnuItem As New clsMenuItem
1
by: Chris Murphy via DotNetMonster.com | last post by:
Hi all, I'm just wondering if any one can help me with this development issue I'm having. I've created a customized treeview control to handle the particular tasks to which I'll be using it. Within...
3
by: RahimAsif | last post by:
I am writing an application that requires the a portion of the main menu to be dynamic. The menu has file, panels, view files and help across the top. The view files sub menu needs to be...
3
by: active | last post by:
I have a mainmenu menuitem that contains a Recently Used Files menuitem If at design time I include a menuitem in the Recently Used Files menuitem collection it will display OK If I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.