C # WinForm TreeView node Add right-click menu and select Node

Source: Internet
Author: User

Transfer from http://www.cnblogs.com/luluping/archive/2010/03/03/1677206.html

(1) To add a TreeView control to the form

(2) Add a ContextMenuStrip control again;

(3) To add a MouseDown event to the TreeView, the code is as follows:

Private void treeview1_mousedown (object sender, mouseeventargs e)         &NBSP, ..... {            if  (e.Button ==  Mousebuttons.right)//Judge you point is not right button              {                point  Clickpoint = new point (E.X, E.Y);                 treenode currentnode = treeview1.getnodeat (ClickPoint );                if  ( Currentnode != null)//Judging you dot is not a node                 &NBSP, ..... {                    switch  (currentnode.name)//depending on the node display different right-click menu, of course, you can let it display the same menu                     &NBSP, ..... {                         case  "Errorurl":                              CurrentNode.ContextMenuStrip = contextMenuStripErrorUrl;                              break;                     }                     treeview1.selectednode = currentnode;//Select this node                  }             }        }


C # WinForm TreeView node Add right-click menu and select Node

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.