2017-03-15 10 views
0

어떻게 든 막혀서 나무 숲을 볼 수 없습니다.TreeNode 클래스를 사용하여 TreeView없이 계층 적으로 구조화 된 데이터 작업

  • 고유 ID 아이들의
  • 부모
  • 목록 : 내가 아주 간단 순간에, 데이터 (약 6000 노드)의 큰 목록을 가지고 : 내가 원하는 무엇

  • 목록 항목

현재 이것은 플랫 데이터이지만 나는 그것의 계층 구조를 만들려면, 그래서 내가 할 수있는 나무 어떤 ID에 대한

  • 의 모든 어린이
  • 목록 루트까지 부모의 목록 행의 특정 깊이에서 UniqueID에 대한

    • 검색 단일 ID
    • (수평, 수직) 항목
    • 위해 항목을 수평 루프
    • 목록 항목

    내가 뭘하려 : 는이 코드로 시작 ..

    Public Dendrogram As List(Of TreeNode) 
    

    과에 모든 노드를 추가 : see link

    <Serializable> _ 
    Public Class TreeNode 
        Private _uniqueID As Integer 
        Private _name As String 
        Private _parentID As Integer 
        Private _depth As Integer 
        Private _children As ArrayList 
        Public Sub New() 
        End Sub 
        Public Sub New(name As String, parentID As Integer) 
         Me.New(0, name, parentID, -1) 
        End Sub 
        Public Sub New(uniqueID As Integer, name As String, parentID As Integer, depth As Integer) 
         _uniqueID = uniqueID 
         _name = name 
         _parentID = parentID 
         _depth = depth 
        End Sub 
        ''' <summary> 
        ''' Gets or sets the unique ID associated with this category 
        ''' </summary> 
        ''' <remarks>Once a non-zero ID has been set, it may not be modified.</remarks> 
        Public Property UniqueID() As Integer 
         Get 
          Return _uniqueID 
         End Get 
         Set 
          If _uniqueID = 0 Then 
           _uniqueID = value 
          Else 
           Throw New Exception("The UniqueID property cannot be modified once it has a non-zero value") 
          End If 
         End Set 
        End Property 
        Public ReadOnly Property Depth() As Integer 
         Get 
          Return _depth 
         End Get 
        End Property 
        ''' <summary> 
        ''' Gets or sets the label for this node 
        ''' </summary> 
        Public Property Name() As String 
         Get 
          Return _name 
         End Get 
         Set 
          _name = value 
         End Set 
        End Property 
        ''' <summary> 
        ''' The ID of the parent node 
        ''' </summary> 
        Public Property ParentID() As Integer 
         Get 
          Return _parentID 
         End Get 
         Set 
          _parentID = value 
         End Set 
        End Property 
        ''' <summary> 
        ''' Gets the children TreeNode objects for this category 
        ''' </summary> 
        ''' <remarks>In .NET 2.0, this can be modified to use generics, and have type ArrayList&lt;TreeNode></remarks> 
        Public Property Children() As ArrayList 
         Get 
          Return _children 
         End Get 
         Set 
          _children = value 
         End Set 
        End Property 
    End Class 
    

    가 내 나무를 만들었습니다. 슈퍼 깨끗하고, 이해할 수, 하지만 기능이 없습니다!

    이것은 나를 another approach으로 데려왔다. 그러나 그것은 나의 목적을 위해 너무 복잡하다.

    .. 그렇다면 MS에서 TreeNode 클래스를 사용하지 않는 이유는 무엇입니까? 하지만 그걸로 연결된 TreeView를 사용하고 싶지 않아요. this 예가 있지만 C 언어로되어있어 VBNet에서 적용 할 수 없습니다 (ITreeNode의 구현이 멈췄습니다).

    내 질문 : I는 "treeView1.Nodes.Add (topNode)"또는 "treeView1.Nodes (0) .Nodes.Find (SEARCHTERM, 참)"실제로없는로 트 리뷰 기능을 사용할 수있는 방법 그것을 내 양식에 담아 야합니다 (시각화하지 않고 데이터를 구조화하기 만하면됩니다).

    나는 이것이 의미가 있으며 누구나 올바른 방향으로 나를 가리킬 수 있기를 바랍니다.

  • 답변

    1

    TreeNodeSystem.Windows.Forms 네임 스페이스에 있지만 실제로는 WinForms에 묶여있는 것 같지 않습니다 (이미 다른 네임 스페이스로 상속 된 것으로 보이므로) 너는 그것을 사용할 수 없는가? 예 :

    Imports System.Windows.Forms 
    
    Sub Main 
        Dim root = New TreeNode("Root") 
        root.Nodes.Add("Node 1") 
        root.Nodes.Add("Node 2") 
        root.Nodes.Add("Node 3") 
        root.Nodes(0).Nodes.Add("Node 1.1") 
        root.Nodes(0).Nodes(0).Nodes.Add("Node 1.1.1") 
        root.Nodes(1).Nodes.Add("Node 2.1") 
        PrintNode(root, 0) 
    End Sub 
    
    ' Define other methods and classes here 
    Sub PrintNode(node As TreeNode, level As Integer) 
        Console.WriteLine("{0}{1}", New String(" ", level * 2), node.Text) 
        For Each child In node.Nodes 
         PrintNode(child, level + 1) 
        Next 
    End Sub 
    

    출력 :

    Root 
        Node 1 
        Node 1.1 
         Node 1.1.1 
        Node 2 
        Node 2.1 
        Node 3 
    
    +0

    이 절대적으로 마크했다! 자세한 답변과 많은 답변을 부탁드립니다. – Alex