Multiple ContextMenus in TreeView

Archived support forum for customers who once purchased a PrimalForms product license. This forum is locked.
This topic is 12 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
lambera
Posts: 21
Last visit: Thu Oct 30, 2014 12:20 pm

Multiple ContextMenus in TreeView

Post by lambera »

First thank you for releasing the TreeView and ContextMenuStrip Spotlights, very helpful. I am currently working with a tree structure that is goes three levels deep and is being loaded dynamicly via an XML file. The structure would be similar to:
Load Balanced Name (VIP)
----- Server
---------- Indexes
There are multiple Server Objects and Index Objects. The VIP, Server, and Indexes are required to have there own ContextMenuStrip, as the actions are only similar to the node set.
The following is a portion of my code used to load the TreeView:

Code: Select all

foreach ($Server in $Servers)
{
	$Name = $Server.Name
	$Collections = $Server.Collection | Select Name -ExpandProperty Name
	$SrvNodes = $treeview1.TopNode.Nodes.Add($Name)
	Foreach ($Collection in $Collections)
		{$ColNodes = $SrvNodes.Nodes.Add($Collection, $Collection, 0, 0)}
}

I attempted to use the following code to load a contextmenustrip for each of the nodes sets, doing this, all Nodes get the last contextmenustrip. This leads me to believe that this setting is global to the $Treeview1 Object, no matter where it is being set. Is this true?

Code: Select all

$treeview1.ContextMenuStrip = $Vse_Vip_Menu
$SrvNodes.ContextMenuStrip = $Vse_Server_Menu
$ColNodes.ContextMenuStrip = $Vse_Col_Menu

Is there a supported method to set a unique contextmenustrip based on the level of the node? I really was hoping that I dont have to do something hacky like using Click Actions with If and ElseIf's.
What does Sapien recommend for the approach on this?
Thanks,
AJ

Edit: If I create the create Tree List View manually I can using the Nodes Collection set a ContextMenuStrip for each one. I need to do this dynamiclly.
lambera2011-12-19 14:02:40
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Multiple ContextMenus in TreeView

Post by davidc »



If you
set the ContextMenuStrip at the TreeView level it will display that ContextMenuStrip
regardless where on the control you click on (including nodes).

If
want a node to show a different ContextMenuStrip, you will need to set the
node's ContextMenuStrip property instead.

If you
don't want to set each individual node's Contextmenustrip property, I recommend
looking at the sample for the ContextMenuStrip Spotlight. The sample demonstrates
how to display the context menu dynamically when you right click on any node in
the TreeView.



As for
the depth you could use the Node
David
SAPIEN Technologies, Inc.
User avatar
lambera
Posts: 21
Last visit: Thu Oct 30, 2014 12:20 pm

Multiple ContextMenus in TreeView

Post by lambera »

Youre example is what I am doing, as listed in my example. Is it because I am also setting one in the sample script block for the root level? Guess Ill keep playing around with this. Thanks. Edit: The problem is that this code doesnt work: $node = $treeview1.Nodes.Add('New node')$node.ContextMenuStrip = $nodeContextMenu
lambera2011-12-19 14:50:10
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Multiple ContextMenus in TreeView

Post by davidc »

I recommend removing the ContextMenuStrip from the TreeView if you want to display it on the nodes only. David
David
SAPIEN Technologies, Inc.
User avatar
lambera
Posts: 21
Last visit: Thu Oct 30, 2014 12:20 pm

Multiple ContextMenus in TreeView

Post by lambera »

I figured this out using my own method. Thanks.
This topic is 12 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.