[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

TreeView Nodes

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
/* ******************* */
  • 2
1 Solution
Bob LearnedCommented:
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.

gumball_chAuthor Commented:
1) .NET 2.0
2) well how can I use this with the above code?
Bob LearnedCommented:

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now