Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Treeviews
Message
From
12/08/2003 13:22:46
 
 
To
12/08/2003 13:04:42
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:
00819475
Views:
10
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