472,784 Members | 1,019 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 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 1294

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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.