Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Treeviews
Message
From
12/08/2003 17:17:40
 
 
To
12/08/2003 17:11:27
Jim Rieck
Quicken Loans/Rock Financial/Title Sourc
Livonia, Michigan, United States
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
00819455
Message ID:
00819612
Views:
13
Jim,

Yep ... I put this in a MouseDown EventHandler of my TreeView base class:
private void oTree_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
  if (e.Button == MouseButtons.Right)
  {
    TreeNode o = (TreeNode)this.GetNodeAt(e.X, e.Y);
    if (o != null)
      this.SelectedNode = o;
  }
}
~~Bonnie



>Bonnie,
>
> Thanks for the suggestion, it worked. I have another problem now. When I click on the treeview I need to know the node that is selected, but the previous node is still selected. For example, if I have nodes A, B, C and D on my treeview A is selected and I right click on C to bring up a menu, A is still selected. Is there a way around this?
>
>Jim
>
>
>>Jim,
>>
>>You need to use a ContextMenu on your Form. In the ContextMenu Popup event, code something like this:
>>
>>private void oContextMenu_Popup(object sender, System.EventArgs e)
>>{
>>  this.oContextMenu.MenuItems.Clear();
>>  MenuItem oItem;
>>
>>  switch (this.oTree.SelectedID)
>>  {
>>    case "First Tree Item" :
>>      oItem = new MenuItem("First Stuff To Do");
>>      oItem.Click += new System.EventHandler(this.oMenu_Handler);
>>      this.oContextMenu.MenuItems.Add(oItem);
>>
>>      oItem = new MenuItem("More First Stuff To Do");
>>      oItem.Click += new System.EventHandler(this.oMenu_Handler);
>>      this.oContextMenu.MenuItems.Add(oItem);
>>
>>      break;
>>
>>    case "Second Tree Item" :
>>      oItem = new MenuItem("Second Stuff To Do");
>>      oItem.Click += new System.EventHandler(this.oMenu_Handler);
>>      this.oContextMenu.MenuItems.Add(oItem);
>>
>>      oItem = new MenuItem("More Second Stuff To Do");
>>      oItem.Click += new System.EventHandler(this.oMenu_Handler);
>>      this.oContextMenu.MenuItems.Add(oItem);
>>
>>      break;
>>  }
>>}
>>
>>private void oMenu_Handler(object sender, System.EventArgs e)
>>{
>>  MenuItem item = (MenuItem)sender;
>>
>>  switch (item.Text)
>>  {
>>    case "First Stuff To Do" :
>>       //etc.
>>       break;
>>  }
>>}
>>
>>
>>HTH,
>>~~Bonnie
>>
>>
>>>All,
>>>
>>> I have an application with a treeview control. I want to be able to rightclick and display a menu. The options in the menu will be determined by the type of item that is clicked on. What is the best way to go about this?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform