c# - How to add a new treeview at the selected node? -
i have treeview 4 levels; parent, child, grandchild, great-grandchild. selectednode @ grandchild level.
what i'm trying create new "treeview" @ grandchild - no, dont wnat create new node "selectednode" (grandchild). should somelike this:
parent child grandchild (new treeview) parent grandchild
great-grandchild child
great-grandchild child grandchild grandchild
it similar parent table mother , father went off , had new childern different spouse other spouse of there existing children.
private sub populaterootlevel() ' query find first round of parent populatenodes(dt, jcatreeview.nodes) end sub
private sub populatenodes(byval dt datatable, byval nodes treenodecollection) each dr datarow in dt.rows dim tn new treenode() tn.text = dr("title").tostring() tn.value = dr("parent_id").tostring() nodes.add(tn)
'if node has child nodes, enable on-demand populating tn.populateondemand = (cint(dr("childnodecount")) > 0) next
end sub
private sub populatesublevel(byval parentid integer, byval parentnode treenode)
' query find children of parent child node count of parent da.fill(dt) populatenodes(dt, parentnode.childnodes)
end sub
protected sub treeview1_treenodepopulate(byval sender object, _ byval e system.web.ui.webcontrols.treenodeeventargs) handles treeview1.treenodepopulate ' add test determine if treeview1 or sub_treeview1 populatesublevel(cint(e.node.value), e.node) end sub
protected sub treeview1_selectednodechanged(byval sender object, byval e system.eventargs) handles treeview1.selectednodechanged
dim selected_parent_id integer = sender.selectednode.value parent_to_new_treeview_populatesublevel(selected_parent_id, sender.selectednode)
end sub
private sub sub_treeview1_populatesublevel(byval parent_id integer, byval parentnode treenode)
' query new children of parents da.fill(dt2) sub_treeview1_populatenodes(dt2, parentnode.childnodes)
end sub
private sub sub_treeview1_populatenodes(byval dt datatable, byval nodes treenodecollection) each dr datarow in dt.rows dim tn treenode = new treenode() 'tn = parentbcnode.nodes.add("new_parent_treeview") ' query child on new parent treeview tn.text = dr("new parent title").tostring() tn.value = dr("new_parent_id").tostring() nodes.add(tn) 'if node has child nodes, enable on-demand populating tn.populateondemand = (cint(dr("childnodecount")) > 0) next end sub
thanks!
you can't that. treeview can not have 1 of child nodes treeview control. thing can assign treeview tag property of treenode, not displayed (obviously). don't understand why want that, unless want different drawing behavior grand-child sub-tree. can make use of treenode.level property find out @ level node is. , again can create custom object(that has required information) , store in treenode.tag property.
Comments
Post a Comment