M,
you can test sender reference, which you get in handler as parameter, for
which menu item invoked the handler. Just cast it to MenuItem and you can
access all properties and methods. You can use Text, Mnemonic or Shortcut at
least.
HTH
Alex
> <see code snippet below>
>
[quoted text clipped - 93 lines]
> }
> }
M - 23 Jul 2004 00:24 GMT
Thanks for answering.
I know I can cast it to the menuitem and get the text but I can only get its
text (a, b or c) but I cannot get its parents text.
I'm guessing that I should add an event handler to the second level menu
items to catch the Popup event. Then record the current active items text.
Something along those lines, I'm not sure though because its not clear right
now.
I am hoping someone would read it and go "oh you just need to do this...."
or like many of my past posts I'll think of the answer about an hour after I
send the original post but that has yet to happen.
> M,
>
[quoted text clipped - 104 lines]
> > }
> > }
AlexS - 23 Jul 2004 00:31 GMT
M,
you can get reference to parent menu using MenuItem.Parent property. From
parent menu you can go up using IsParent and GetMainMenu
I am not sure now what is your problem
HTH
Alex
> Thanks for answering.
>
[quoted text clipped - 120 lines]
> > > }
> > > }
M - 23 Jul 2004 14:10 GMT
ok. The other responder Jacob showed me the light.
I was having a mental block and didn't make the connection to the parent
item being a menuitem itself. I kept thinking 'ok I have the parent item
which is a menu, how do I figure out which menuitem was the active one."
Now it is clear.
Thanks for you help though
Best Regards
M
> M,
>
[quoted text clipped - 138 lines]
> > > > }
> > > > }
Hi,
I'm just wondering... what you're adding now is a reference to the same menu
item to all the subsubmenuitems. Try replacing your MyPopUpSubSubMenu with
public class MyPopUpSubSubMenu : ContextMenu
{
static int i = 0;
public MyPopUpSubSubMenu()
{
MenuItems.Add(new MenuItem("a" + i++));
MenuItems.Add(new MenuItem("b"));
MenuItems.Add(new MenuItem("c"));
MenuItems.Add(new MenuItem("d"));
}
};
and you'll see that there's only one reference being added (namely the
same). Instead try using
MenuItems[0].MergeMenu(new MyPopUpSubSubMenu());
MenuItems[1].MergeMenu(new MyPopUpSubSubMenu());
MenuItems[2].MergeMenu(new MyPopUpSubSubMenu());
MenuItems[3].MergeMenu(new MyPopUpSubSubMenu());
in MyPopUpSubMenu and you'll see the difference.
As far as I can see this creates a problem regarding the Parent property. I
tried coding something different:
ContextMenu popup = new ContextMenu();
popup.MenuItems.Add(new MenuItem("A"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("1"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("2"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("3"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("4"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("a"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("b"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("c"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("d"));
popup.MenuItems.Add(new MenuItem("B"));
popup.MenuItems.Add(new MenuItem("C"));
popup.MenuItems.Add(new MenuItem("D"));
and used the following in the WhoseCallingMe function to traverse from child
to parent:
public void WhoseCallingMe(object sender, System.EventArgs e)
{
MenuItem menuItem = (MenuItem) sender;
string path = "";
while(menuItem.GetType() == menuItem.Parent.GetType())
{
path = "-> " + menuItem.Text + path;
menuItem = (MenuItem) menuItem.Parent;
}
path = "-> " + menuItem.Text + path;
MessageBox.Show(path);
}
If you know the menuitems on beforehand the individual menu items could get
their own event handler, though that could lead up to quite a lot of event
handlers.
What exactly are you trying to do? It sounds as if you want to create your
own ContextMenu class?
Hope this helps a bit!

Signature
Yours sincerely,
Jacob Munk-Stander | http://jacob.munk-stander.dk
> <see code snippet below>
>
[quoted text clipped - 93 lines]
> }
> }
M - 23 Jul 2004 14:17 GMT
ok great, I've got it now. Thanks
This line > menuItem = (MenuItem) menuItem.Parent;
cleared it up for me. I kept thinking that I have the parent but how do I
determine which menuitem was the 'active' one. I forget it was a menuitem
itself.
And thanks for pointing out the reference to the same menu item to all the
subsubmenuitems, that would of cause some problems.
Right now I know the menu items but at some point I'd like to make the
second tier menuitems added dynamically as the users see fit but that's down
the road a little bit.
Actually I'm going to have one handler for all the items. In the one handler
I needed to determine which second level item (and possibly first level too)
called me so it can open the correct form.
Thanks for your help. I do appreciate it.
Best Regards,
M
> Hi,
> I'm just wondering... what you're adding now is a reference to the same menu
[quoted text clipped - 169 lines]
> > }
> > }