0
我有一個四級樹視圖;父母,孩子,孫子,曾孫。我選的節點在孫子級別。如何在選定的節點添加新的樹視圖?
我想要做的是在孫子創建一個新的「Treeview」 - 不,我不想創建一個新的節點到「selectednode」(孫子)。所以它應該是somelike這樣的:
父 孩子 孫子(新TreeView控件),這是孫子
家長 曾孫子女
曾孫子女 孫子孫女
這將是類似於母體表中,母親和父親離開,並與除了配偶之外的其他配偶有現有子女的新配偶。
Private Sub PopulateRootLevel()
' query to find first round of parent
PopulateNodes(dt, JCATreeView.Nodes)
End Sub
Private Sub PopulateNodes(ByVal dt As DataTable, ByVal nodes As TreeNodeCollection)
For Each dr As DataRow In dt.Rows
Dim tn As New TreeNode()
tn.Text = dr("TITLE").ToString()
tn.Value = dr("Parent_ID").ToString()
nodes.Add(tn)
'If node has child nodes, then enable on-demand populating
tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
Next
End Sub
Private Sub PopulateSubLevel(ByVal parentid As Integer, ByVal parentNode As TreeNode)
' query to find children of parent with child node count of parent
da.Fill(dt)
PopulateNodes(dt, parentNode.ChildNodes)
End Sub
Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate
' add a test to determine if this is from TreeView1 or Sub_TreeView1
PopulateSubLevel(CInt(e.Node.Value), e.Node)
End Sub
Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged
Dim selected_parent_id As Integer = sender.SelectedNode.value
Parent_to_NEW_TREEVIEW_PopulateSubLevel(selected_parent_id, sender.SelectedNode)
End Sub
Private Sub Sub_TreeView1_PopulateSubLevel(ByVal parent_id As Integer, ByVal parentNode As TreeNode)
' Query to get new children of parents
da.Fill(dt2)
Sub_TreeView1_PopulateNodes(dt2, parentNode.ChildNodes)
End Sub
Private Sub Sub_TreeView1_PopulateNodes(ByVal dt As DataTable, ByVal nodes As TreeNodeCollection)
For Each dr As DataRow In dt.Rows
Dim tn As TreeNode = New TreeNode()
'tn = parentBCNode.Nodes.Add("NEW_PARENT_TREEVIEW")
' query to get child on the 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, then enable on-demand populating
tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
Next
End Sub
新的「treeview」只是另一個節點。真正的問題是應該在哪裏添加新節點?它是選擇節點的兄弟嗎? – 2011-02-09 17:49:27