Why can't I get my ContextMenu to popup ?

G

Guest

I overrided a TreeView control and then overrided it's MouseClick event like
so:

protected override void OnMouseClick(MouseEventArgs e)
{
// base.OnMouseClick(e);
TreeNode node = this.GetNodeAt(e.Location);
this.SelectedNode = node;


if (e.Button == MouseButtons.Right)
{
Console.WriteLine("show menu");
blockMenu.Show(this, e.Location);
}
}

when I right click I see the text "show menu" in my console but the menu
never shows up - why?
 
G

Guest

I figured out why...

In my constructor I created 3 ContextMenus. My plan was to have 3 separate
menus and in my mouse event I would simply toggle which one shows up
(setting the TreeView's ContextMenu in a switch)

I also thought I was going to be clever by creating onl yone instance of the
MenuItem objects and just simply add it to multiple menus if I wanted that
option in multiple menus

Turns out the ContextMenu "consume" the MenuItem so if I add it to one
context menu, and then add it to another after that, the second one stakes
his claim on it and the first one loses it!

It's really kind of bizarre behavior to me, but that's how it is!

it turned out the "blockMenu' I tried to show in my code was the one menu
that had only default menuitems that the other menus shared so it was
basically empty after the other 2 menus were loaded
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top