Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Context menu on a TreeView

Context menu on a TreeView

Scheduled Pinned Locked Moved C#
data-structureshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sonu T
    wrote on last edited by
    #1

    hi all, i have a Tree with 3 modes. each tree has 1 child. i need to create 2 context menus;one for all the nodes and the other for all the children programmatically kindly help

    Sonu

    S 1 Reply Last reply
    0
    • S Sonu T

      hi all, i have a Tree with 3 modes. each tree has 1 child. i need to create 2 context menus;one for all the nodes and the other for all the children programmatically kindly help

      Sonu

      S Offline
      S Offline
      Schmullus
      wrote on last edited by
      #2

      Hi, have a look to my example: I created a windows-application with a form and one 'TreeView'-component named treeView1 in my code. The only code is written within the Load-event of the form: private void Form1_Load(object sender, EventArgs e) { ContextMenu myRootContextMenu = new ContextMenu(); myRootContextMenu.MenuItems.Add("Edit Root"); ContextMenu myChild1ContextMenu = new ContextMenu(); myChild1ContextMenu.MenuItems.Add("Edit Child 1"); ContextMenu myChild2ContextMenu = new ContextMenu(); myChild2ContextMenu.MenuItems.Add("Edit Child 2"); **TreeNode rootTreeNode = new TreeNode("Root");** rootTreeNode.ContextMenu = myRootContextMenu; rootTreeNode.Nodes.Add("First Node"); rootTreeNode.Nodes[0].ContextMenu = myChild1ContextMenu; rootTreeNode.Nodes.Add("Second Node"); rootTreeNode.Nodes[1].ContextMenu = myChild2ContextMenu; treeView1.Nodes.Add(rootTreeNode); } I created one root treenode 'rootTreeNode' TreeNode rootTreeNode = new TreeNode("Root"); and added two child nodes: rootTreeNode.Nodes.Add("First Node"); rootTreeNode.Nodes.Add("Second Node"); After that, I added this treenode to the TreeView 'treeView1' of the Form. treeView1.Nodes.Add(rootTreeNode); Now we come to the context-menues: I created one root context-menu, and gave it a description ContextMenu myRootContextMenu = new ContextMenu(); myRootContextMenu.MenuItems.Add("Edit Root"); and with the property 'ContextMenu' of the rootTreeNode rootTreeNode.ContextMenu = myRootContextMenu; I made the assignment. The context-menues for the child nodes are ContextMenu myChild1ContextMenu = new ContextMenu(); myChild1ContextMenu.MenuItems.Add("Edit Child 1"); ContextMenu myChild2ContextMenu = new ContextMenu(); myChild2ContextMenu.MenuItems.Add("Edit Child 2"); and assigned in the same way. Hope this helps a little bit Regards Erik

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups