C # Runtime Edit node Rename

Source: Internet
Author: User

method One:intNodeindex =0; BOOLNodeChanged =false; //Right click to enter the modified state        Private voidTreeview1_nodemouseclick (Objectsender, TreeNodeMouseClickEventArgs e) {            if(E.button = =mousebuttons.right) {e.node.beginedit (); }        }         Private voidTreeview1_afterlabeledit (Objectsender, NodeLabelEditEventArgs e) {Nodeindex=E.node.index; NodeChanged=true; E.node.endedit (true ); }         Private voidTreeview1_nodemousehover (Objectsender, TreeNodeMouseHoverEventArgs e) {            if(NodeChanged = =true)            {                //Save the data to the database hereMessageBox.Show (Treeview1.nodes[nodeindex].                 Text); NodeChanged=false; }        }
Method Two:
method Two: Use of MouseClick and AfterLabelEdit, Treeview1.labeledit=trueThis sentence is indispensable: PublicForm1 () {InitializeComponent ();  This. load+=NewEventHandler (Form1_Load); Treeview1.mouseclick+=NewMouseEventHandler (Treeview1_mouseclick); Treeview1.afterlabeledit+=NewNodelabelediteventhandler (treeview1_afterlabeledit);} Private voidForm1_Load (Objectsender, EventArgs e) {     for(inti =0; I <Ten; i++) {TREEVIEW1.NODES.ADD ("TV"+i.tostring ()); Treeview1.nodes[i]. Nodes.Add ("TVC"+i.tostring ()); } Treeview1.labeledit=true;//not missing} Private voidTreeview1_mouseclick (Objectsender, MouseEventArgs e) {TreeView TV= (TreeView) sender;//get TreeView    if(E.button = = mousebuttons.right)//determine if the right mouse button    {        if(TV. SelectedNode! =NULL)//determine if a selection node existsTV.    Selectednode.beginedit (); }}Private voidTreeview1_afterlabeledit (Objectsender, NodeLabelEditEventArgs e) {    stringNewtxt = E.label;//Get new text//string id = e.node.text;//get the original text//Make your update operation }

Original address: Http://www.cnblogs.com/better-than-ever/p/3222883.html thank Yumbo Lord. It's just a record here.

C # Runtime Edit node Rename

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.