2011-02-09 3 views
0

4 레벨의 트리 뷰가 있습니다. 부모, 자녀, 손자, 증손자. 내가 선택한 노드가 손자 레벨에 있습니다.선택한 노드에서 새 트리 뷰를 추가하는 방법은 무엇입니까?

내가하려는 것은 손자에게 새로운 "Treeview"를 만드는 것입니다. 아니요, "선택한 노드"(손자)에 새 노드를 만들지 않습니다. 그래서이 somelike해야한다 :

부모 아이 손자 (트 리뷰) 손자
이었다 부모 증손 자녀
증손 자녀 손자의 손자

그것은 부모 유사 할 것 어머니와 아버지가 떠나서 기존 자녀의 배우자가 아닌 다른 배우자와 함께 새로운 자녀를 낳았습니다.

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 
+0

새로운 "treeview"는 다른 노드입니다. 진짜 문제는 새로운 노드가 추가되어야하는 곳입니까? 선택한 노드의 형제입니까? –

답변

0

당신은 그렇게 할 수 없습니다. TreeView는 자식 노드 중 하나로서 다른 TreeView 컨트롤을 가질 수 없습니다. 당신이 할 수있는 유일한 일은 TreeView를 TreeNode의 tag 프라퍼티에 할당하는 것이지, 그것은 분명히 표시되지 않을 것입니다. 그 자식 하위 트리에 대해 다른 그리기 동작을 원한다면 왜 그렇게하고 싶은지 이해할 수 없습니다. treeNode.Level 속성을 사용하여 해당 노드가 어느 수준인지 확인할 수 있습니다. 그리고 다시 원하는 모든 정보를 가진 사용자 정의 객체를 만들어 treeNode.Tag 속성에 저장할 수 있습니다.

관련 문제