Asp.net c # delete node and node rename code

Source: Internet
Author: User

Asp tutorial. net c # delete node and node rename code
Private void menuitemdelete_click (object sender, system. eventargs e)
{
Try
{
If (messagebox. show (this, "delete node <" + treeview. selectednode. text. trim () + ">, and the corresponding information will also be deleted. Are you sure you want to delete it? "," Information ", messageboxbuttons. okcancel, messageboxicon. question) = dialogresult. OK)
{
// Determine whether the selected node has a lower-level node
If (treeview. selectednode. nodes. count = 0)
{
// Delete a node
Treenode delenode = treeview. selectednode;
If (file. exists (this. richtextboxpicturename) file. delete (this. richtextboxpicturename );
Int rows = mybindtree. position;
Treeview. nodes. remove (delenode );
Dataset. tables ["tree"]. rows [rows]. delete ();
}
Else
Messagebox. show ("delete the subnode in this node first! "," Information ", messageboxbuttons. OK, messageboxicon. information );
}
}
Catch (exception te)
{
Messagebox. show (this, te. message, "errordelete", messageboxbuttons. OK, messageboxicon. warning );
}
}


6. Rename a node
Private void menuitemrename_click (object sender, system. eventargs e)
{
Treenode myselectednode = treeview. selectednode;
If (myselectednode! = Null)
{
Treeview. selectednode = myselectednode;
Treeview. labeledit = true;
Myselectednode. beginedit ();
}
Else
Messagebox. show ("no tree node selected. n", "invalid selection ");
}

/// <Summary>
/// Return the maximum nodeid number of the specified table, that is, the tag of the currently selected node.
/// </Summary>
/// <Param name = "dt"> Data Table </param>
/// <Param name = "columnname"> data column </param>
/// <Returns> maximum nodeid number </returns>
Private int maxrecordnumber (datatable dt, string columnname)
{
Int number = 0;
Dataview dv = dt. defaultview;
Dv. sort = columnname + "asc"; // a string containing the column name, followed by "asc" (ascending) or "desc" (descending ). By default, columns are listed in ascending order. Multiple columns can be separated by commas.
Foreach (datarow dr in dt. rows)
{
Number = convert. toint16 (dr [columnname]. tostring (). trim ()> number? Convert. toint16 (dr [columnname]. tostring (). trim (): number;
}
Return number;
}

/// <Summary>
/// Add or delete nodes in the data table
/// </Summary>
/// <Param name = "adddeletenode"> nodes to be added or deleted </param>
/// <Param name = "parentnodeid"> add or delete the parent node of the node </param>
/// <Param name = "adddeletetag"> add/delete node flag (add indicates adding a node, delete indicates deleting a node, and case-insensitive) </param>
Private void adddeletenode (treenode adddeletenode, string parentnodeid, string adddeletetag)
{
Try
{
If (adddeletetag. toupper () = "add ")
{
Object key = parentnodeid;
Datarow dr = dataset. tables ["tree"]. rows. find (key );
Datarow drnew = dataset. tables ["tree"]. newrow ();
If (dr! = Null)
{
Drnew ["parentid"] = dr ["nodeid"];
}
Else
{
Drnew ["parentid"] = rootnodetag;
}
Drnew ["nodeid"] = (int) adddeletenode. tag;
Drnew ["nodename"] = adddeletenode. text. trim ();
Dataset. tables ["tree"]. rows. add (drnew );
}
Else
{
If (adddeletetag. toupper () = "delete ")
{
Dataset. tables ["tree"]. rows [mybindtree. position]. delete ();
}
}
}
Catch (exception te)
{
Messagebox. show (this, te. message, "error", messageboxbuttons. OK, messageboxicon. warning );
}
}

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.