TreeView Nodes

Posted on 2006-04-28
Last Modified: 2010-04-23
Hi dot NET cracks

I have the following problem. I build up a TreeView out of a database (storedProcedure). Well the Treeview looks nice, but I need two more functionality in.
1. I need the idSharedDocStruct (it's a GUID) on each node available to reference it (as a key)
2. I want to sort that tree alphabetically

Has one of you a tip, how to do this two things?

Thank you

/* *********** */
        Dim SelectCmdString As String = "usp_getStructureHierarchy1 'root','" & txtLogonUser.Text & "';"
        Dim mySqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(SelectCmdString, sqlConn)

        Dim ds As New DataSet()
        mySqlDataAdapter.Fill(ds, "struct")

        Dim dt As DataTable

        dt = ds.Tables(0) ' or whatever number table has the good stuff...
        Dim tmpNode As TreeNode
        Dim tmpItem As treeListItem
        Dim treeList As New ArrayList
        Dim dtr As New Data.DataTableReader(dt)

        While dtr.Read
            tmpNode = New TreeNode(dtr.Item("nvchSharedDocStructTitle").ToString.Trim)

            If dtr.Item("idSharedDocStructParent").ToString = "" Then
                tmpItem = New treeListItem(CType(dtr.Item("idSharedDocStruct"), Guid), Nothing, tmpNode)
                tmpItem = New treeListItem(CType(dtr.Item("idSharedDocStruct"), Guid), CType(dtr.Item("idSharedDocStructParent"), Guid), tmpNode)
            End If

        End While

        For Each tmpItem In treeList
            If tmpItem.theParentID = Nothing Then
                'this is a root node
                'this is a child node, locate parent and add threre
                For Each tmpItem2 In treeList
                    If tmpItem.theParentID = tmpItem2.theStructID Then
                        'this is the parent so add here
                    End If
            End If

/* ************* */
Public Class treeListItem

    Private _theNode As TreeNode
    Private _theStructID As Guid
    Private _theParentID As Guid

    Public ReadOnly Property theNode() As TreeNode
            Return _theNode
        End Get

    End Property
    Public ReadOnly Property theStructID() As Guid
            Return _theStructID
        End Get

    End Property
    Public ReadOnly Property theParentID() As Guid
            Return _theParentID
        End Get

    End Property
    Public Sub New(ByVal sID As Guid, ByVal pID As Guid, ByVal tNode As TreeNode)
        _theNode = tNode
        _theStructID = sID
        _theParentID = pID
    End Sub

End Class
/* ******************* */
Question by:gumball_ch
    LVL 96

    Expert Comment

    by:Bob Learned
    1) What .NET version are you using?

    2) 2005 has the Sort method coupled with the TreeViewNodeSorter property, which specifies an IComparer instance to sort.


    Author Comment

    1) .NET 2.0
    2) well how can I use this with the above code?
    LVL 96

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now