Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Treeview + CheckBox + ContextMenu
Message
De
14/02/2004 16:25:15
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00877414
Message ID:
00877420
Vues:
22
Eric,

You don't really have to mess with clicks and other mouse events to display and capture ContextMenus. I think that is what's causing you problems (although I haven't used a TreeView with checkboxes in it, but I doubt that this is the problem). I'm sorry to have to post this in C# rather than VB, but I tried to use the C#-to-VB converters and they didn't particularly like the way C# does delegates and event handlers. I hope you can figure it out:
// Set the Tree's ContextMenu
this.oTree.ContextMenu = this.oContextMenu

// Set the ContextMenu Popup event handler
this.oContextMenu.Popup += new System.EventHandler(this.oContextMenu_Popup);

private void oContextMenu_Popup(object sender, System.EventArgs e)
{
  this.oContextMenu.MenuItems.Clear();
  MenuItem oItem;

  // Create all the appropriate ContextMenu items. This can vary
  // depending on which node in the TreeView was clicked. I have a Node class
  // defined in the control that adds additional functionality to the TreeNode class,
  // so I can tell which type of Node has been selected
  MyTreeNode node = (MyTreeNode)this.oTree.SelectedNode;
  if (node.IsTypeOne)
  {
    // Create one type of context menu
    oItem = new MenuItem("Text For Type One");
    oItem.Click += new System.EventHandler(this.oMenu_Handler);
    this.oContextMenu.MenuItems.Add(oItem);
  }
  else if (node.IsTypeTwo)
  {
    // Create another type of context menu
    oItem = new MenuItem("Text For Type Two");
    oItem.Click += new System.EventHandler(this.oMenu_Handler);
    this.oContextMenu.MenuItems.Add(oItem);
  }
}

private void oMenu_Handler(object sender, System.EventArgs e)
{
  MenuItem oItem = (MenuItem)sender;

  // Process whichever ContextMenu item was selected
  if (item.Text == "Text For Type One")
    // code to process type one
  else if (item.Text == "Text For Type Two")
    // code to process type two
}
~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform