Hi Andersch,
Do you mean that you would like to show the same context menu strip no
matter on which tree node you right-click and just disable some items in
the context menu strip depending on the selected tree node?
If so, I think you could set the ContextMenuStrip property of the treeview
to the context menu strip and handle the Opening event of the context menu
strip, which occurs when the context menu strip is opening
The following is a sample for you. The sample requires you to set up a
Windows application project, add a TreeView control and a ContextMenuStrip
onto the form, add some nodes into the treeview and add some items into the
context menu strip.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.contextMenuStrip1.Opening += new
CancelEventHandler(contextMenuStrip1_Opening);
}
void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
this.contextMenuStrip1.Items[0].Enabled = false;
this.contextMenuStrip1.Items[1].Enabled = false;
this.contextMenuStrip1.Items[2].Enabled = false;
switch (this.treeView1.SelectedNode.Index)
{
case 0 :
this.contextMenuStrip1.Items[0].Enabled = true;
break;
case 1:
this.contextMenuStrip1.Items[1].Enabled = true;
break;
case 2:
this.contextMenuStrip1.Items[2].Enabled = true;
break;
}
}
}
Build the project and run it. When you select the first tree node and
right-click on it, the context menu strip shows up and only the first item
in the context menu strip is enabled.
Hope this helps.
If the above sample isn't what you want, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.