Generic Tree : Generic Tree « Generics « VB.Net

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VB.Net » Generics » Generic TreeScreenshots 
Generic Tree
Generic Tree

Imports System.Collections

Public Class MainClass

   Public Shared Sub Main()
        Dim rootNode, child1 As TreeNode(Of Employee)
        rootNode = New TreeNode(Of Employee)(New Employee(111"A"))
        child1 = rootNode.AddChild(New Employee(222"B"))
        rootNode.AddChild(New Employee(333"C"))
        child1.AddChild(New Employee(444"D"))
        child1.AddChild(New Employee(555"E"))

        Console.WriteLine(rootNode)

   End Sub


End Class


Public Class TreeNode(Of T)
    Public Data As T
    Private _childNodes As ArrayList

    Public Sub New(ByVal nodeData As T)
        Me.Data = nodeData
        Me._childNodes = New ArrayList
    End Sub

    Public ReadOnly Property Children() As TreeNode(Of T)()
        Get
            Return Me._childNodes.ToArray()
        End Get
    End Property

    Default Public ReadOnly Property Item(ByVal index As LongAs TreeNode(Of T)
        Get
            Return Me._childNodes(index)
        End Get
    End Property

    Public Function AddChild(ByVal nodeData As TAs TreeNode(Of T)
        Dim newNode As TreeNode(Of T= New TreeNode(Of T)(nodeData)
        Me._childNodes.Add(newNode)
        Return newNode
    End Function

    Overrides Function ToString() As String
        Return Me.Data.ToString()
    End Function

End Class


Public Class Employee
    Private _id As Integer
    Private _name As String

    Public Sub New(ByVal id As Integer, ByVal name As String)
        Me._id = id
        Me._name = name
    End Sub

    Public Overrides Function ToString() As String
        Return Me._name
    End Function

End Class


           
       
Related examples in the same category
1. Define and use a generic Tree data structureDefine and use a generic Tree data structure
w___w_w_.j__a___va__2__s_.__co__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.