I want to Change the dropdown menuItems from the menustrip's 1st item
(Action) to be the same as the contextmenustrip that would pop-up for the
node selected in a Treeview control. Here is the complete method. Thank you
very much.
private void ppTree_NodeMouseClick(object sender,
TreeNodeMouseClickEventArgs e)
{
int index = 0;
string nodeTxt = e.Node.Text;
ToolStripMenuItem actionMenu =
(ToolStripMenuItem)mainMenu.Items[0];
actionMenu.DropDownItems.Clear();
if (nodeTxt != null)
{
switch (nodeTxt)
{
case "Unity Administration":
ToolStripItemCollection menuItems =
rootMenuStrip.Items;
actionMenu.DropDownItems.
while (menuItems.Count >= 0)
{
actionMenu.DropDownItems.Add(menuItems[index]);
index++;
}
if (e.Button.ToString() == "Right")
rootMenuStrip.Show(ppTree, e.Location);
break;
case "Contexts":
ToolStripItemCollection contextsMenuItems =
contextsMenuStrip.Items;
//actionMenu.DropDownItems.AddRange(contextsMenuItem s);
while (contextsMenuItems.Count 0)
{
actionMenu.DropDownItems.Add(contextsMenuItems[index]);
index++;
}
if (e.Button.ToString() == "Right")
contextsMenuStrip.Show(ppTree, e.Location);
break;
case "Computers":
ToolStripItemCollection computersMenuItems =
contextsMenuStrip.Items;
actionMenu.DropDownItems.AddRange(computersMenuIte ms);
if (e.Button.ToString() == "Right")
RefreshHelpMenuStrip.Show(ppTree, e.Location);
break;
case "Groups":
ToolStripItemCollection groupsMenuItems =
contextsMenuStrip.Items;
actionMenu.DropDownItems.AddRange(groupsMenuItems) ;
if (e.Button.ToString() == "Right")
RefreshHelpMenuStrip.Show(ppTree, e.Location);
break;
case "Users":
ToolStripItemCollection usersMenuItems =
contextsMenuStrip.Items;
actionMenu.DropDownItems.AddRange(usersMenuItems);
if (e.Button.ToString() == "Right")
RefreshHelpMenuStrip.Show(ppTree, e.Location);
break;
case "Reports":
ToolStripItemCollection reportsMenuItems =
contextsMenuStrip.Items;
actionMenu.DropDownItems.AddRange(reportsMenuItems );
if (e.Button.ToString() == "Right")
reportsMenuStrip.Show(ppTree, e.Location);
break;
default://Maybe it's a context node
if (ppTree.SelectedNode.Parent != null)
{
if (ppTree.SelectedNode.Parent.Name == "Contexts")
contextMenuStrip.Show(ppTree, e.Location);
}
//test.MyTestMethod("COM INTEROP TEST");
break;
}//end switch
}
}
--
Thanks.
"Jon Skeet [C# MVP]" wrote:
Pucca <Pu***@discussions.microsoft.comwrote:
Hi: Below is the error I got from the 2 lines of code below. I don't
understand why and how to correct it. The actionMenu.DropDownItems has 0
item in its collection at the time of the code. Thanks.
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred
in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and
less than the size of the collection.
ToolStripItemCollection contextsMenuItems =
contextsMenuStrip.Items;
.AddRange(contextsMenuItems);
..AddRange(contextsMenuItems) isn't a valid statement, to start with.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too