|
-
Aug 28th, 2000, 11:59 AM
#1
Thread Starter
Hyperactive Member
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?
-
Aug 28th, 2000, 12:10 PM
#2
Lively Member
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.
-
Aug 28th, 2000, 12:19 PM
#3
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)
-
Aug 28th, 2000, 12:23 PM
#4
...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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|