Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
TreeView w/ ContextMenu...
Message
General information
Forum:
ASP.NET
Category:
Menus
Environment versions
Environment:
VB.NET 1.1
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01101212
Message ID:
01101230
Views:
8
This message has been marked as the solution to the initial question of the thread.
>I have a TreeView that uses a ContextMenu. What I need to do it Enable/Disable certain items in the ContextMenu based on what is selected in teh TreeView. Problem is, that I am finding it difficult to find where the proper place is to place my code. When the user Right-Clicks, the ContectMenu pops up before my code to Enable/Disable its items can run. I tried TreeView_AfterSelect, TreeView_BeforeSelect, TreeView_Click, TreeView_MouseUp and ContectMenu_PopUp.

Ben,
This is what I do in one of my treeviews: I use the MouseDown event, something like this
private void treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
	TreeNode treenode = this.treeView1.GetNodeAt(e.X, e.Y);
	if (treenode != null)
	{
		if (e.Button == MouseButtons.Right)
		{
			this.PrepareContextMenu(treenode);
		}
	}
}
In the PrepareContextMenu() method I enable/disable the context menu items. I haven't had any problems with this approach in either 1.1 or 2.0.

In 2.0 (I don't know if it is there in 1.1) the ContextMenuStrip has an Opening event which I sometimes use to prepare the contextmenu before opening.

Hope this helps you.
Einar
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform