+ Reply to Thread
Results 1 to 3 of 3

TreeView Help

Hybrid View

  1. #1
    Registered User
    Join Date
    08-21-2009
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: TreeView Help

    Every time I try the code above or something as simple as

    TV1.Nodes.Add , , "root", "Root Item"
    I get an error indicating the 'key is not unique'

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: TreeView Help

    Each Nodes key must be unique.

    See the attached. There tree contents is on the worksheet.

    Private Sub UserForm_Initialize()
    
        Dim rngTreeData As Range
        Dim lngRow As Long
        Dim strNodeKey As String
        Dim strRelativeNode As String
        Dim strText As String
        
        Set rngTreeData = Range("A1").CurrentRegion
        
        With rngTreeData
            For lngRow = 2 To .Rows.Count
                strNodeKey = .Cells(lngRow, 1)
                strRelativeNode = .Cells(lngRow, 2)
                strText = .Cells(lngRow, 3)
                    
                If strRelativeNode = "" Then
                    ' root
                    TreeView1.Nodes.Add , , strNodeKey, strText
                Else
                    TreeView1.Nodes.Add strRelativeNode, tvwChild, strNodeKey, strText
                End If
            Next
        End With
        
    End Sub
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1