Implementation of tree functions in ASP. NET (2)

Source: Internet
Author: User
   2. add and delete Tree nodes

To add, delete, or modify a node in a Treeview, you only need to use the add, remove, and other methods of the nodes attribute. It is worth noting that. in net, the nodes set of Treeview is different from that in vs6.0. vs6.0 is a large set, while. in. net, each node in the hierarchy has the nodes attribute. The addition, deletion, and modification of Tree nodes are significantly different from those of vs6.0, especially when a tree node is deleted.

Private sub butadd_click (byval sender as system. Object, byval e as system. eventargs) handles butadd. click' Add a subnode under the selected node
Dim tmpnd as new treenode (), ndsel as treenode
Tmpnd. ID = getnewid ()
Ndsel = treeview1.getnodefromindex (treeview1.selectednodeindex) 'selected node
Tmpnd. Text = "new node"
Ndsel. nodes. Add (tmpnd)
Dim myrow as datarow
Myrow = Ds. Tables ("Tree"). newrow ()
Myrow ("node_name") = tmpnd. ID
Myrow ("node_descript") = "new node" & tmpnd. ID & "_" & ndsel. ID
Myrow ("parent_name") = ndsel. ID
DS. Tables ("Tree"). Rows. Add (myrow)
End sub
Private sub butdele_click (byval sender as object, byval e as system. eventargs) handles butdele. click' Delete the selected node
Dim idx as string = treeview1.selectednodeindex ()
Getndcol (idx). Remove (treeview1.getnodefromindex (idx ))
Dim DV as new dataview (), recno as integer
DV. Table = Ds. Tables ("Tree ")
DV. rowfilter = "nodeid =" & ndid
DV. Delete (0)
End sub
Private function getndcol (byval idx as string) as treenodecollection
'Obtain the nodes set of the parent node of the selected node.
Dim CNT as integer, I as integer
Dim tmpnds as treenodecollection
Dim idxs () as string
Idxs = Split (idx ,".")
CNT = ubound (idxs)
If CNT = 0 then
Tmpnds = treeview1.nodes
Else
Tmpnds = treeview1.nodes (CINT (idxs (0). Nodes
For I = 1 to CNT-1
Tmpnds = tmpnds (CINT (idxs (I). Nodes
Next
End if
Return tmpnds
End Function

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.