Results 1 to 4 of 4

Thread: easy imagelist/treeview question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Thumbs up

    The following code that I use to populate a treeview control
    gives me an imagelist error.
    Code:
    Private Sub RefreshNodes()
    'refresh TreeView
    
    On Error GoTo Database_Error
    
    Dim MyNode As Node
    
    tvUsers.Nodes.Clear
    
    Set MyNode = tvUsers.Nodes.Add(, , "Users", "Users")
    
    Adodc1.Recordset.MoveFirst
    Do Until Adodc1.Recordset.EOF
    'establish node with USER as both key and text
    'this is where the image list error occurs
        Set MyNode = tvUsuarios.Nodes.Add("Users", tvwChild, Adodc1.Recordset.Fields("USER").Value, 
    Adodc1.Recordset.Fields("USER").Value, imgLTreeView, 0)
        MyNode.EnsureVisible
        Adodc1.Recordset.MoveNext
    Loop
    
    ShowUserData (tvUsers.Nodes(2).Text)
    
    Exit Sub
    
    Database_Error:
        Select Case Err.Number
            Case 2147217885 'reference to a record that does not exist
                Resume Next
            Case Else
                MsgBox ErrFunction(Err.Description, Err.Number, Err.Source, Me.Name, Screen.ActiveControl.Name), vbCritical
        End Select
    
    End Sub
    The error is "Image List must be initialized before it can be used." This has to be easy, so how is it done?

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Posts
    94
    You need to put pictures into the imagelist before assigning it to the treeview. You can right click on the image list and select properties to add images. Or you can use imagelist1.listimages.add method.

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    The Image argument of the Add method of the Nodes collection should be an Index or a Key value and not the ImageList object.
    Code:
    Set MyNode = tvUsuarios.Nodes.Add("Users", tvwChild, _
     Adodc1.Recordset.Fields("USER").Value, _
     Adodc1.Recordset.Fields("USER").Value, _
     imgLTreeView, 0) 'the last argument can't be zero either
    Change it to something like this:
    Code:
    Set MyNode = tvUsuarios.Nodes.Add("Users", tvwChild, Adodc1.Recordset.Fields("USER").Value, 
    Adodc1.Recordset.Fields("USER").Value, 1, 1)

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    ...and an other thing; make sure you have set the ImageList property of the TreeView to a valid ImageList object.

    Good luck!

Posting Permissions

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



Click Here to Expand Forum to Full Width