Avatar of Thirt
Thirt asked on

Problems using Imagelist control with treeview

I'm not that familar with the treeview control but learning. I'm using a treecontrol to list all the master and sub projects (parent/child) for a given client. I've gotten to the point where I now need to add an image for the node. If the project is closed, I have a red X image, and if the project is open display a green check.

I would prefer not to refer to the images by filename. I would rather keep a local lookup table in the MDB front end client, as that I have control over. But I can't even get this to work refenceing the picture as a local file.

I've been using the MS help page here: http://msdn.microsoft.com/en-us/library/aa443198(VS.60).aspx

But it's confued me and I'm really starting to butcher this up. So I need some help

I would like to build up the imagelist "istatus" with the two images, and then apply it to the Nodes.add by the imagelist refernce number.

I can't get the image added to the control using the local table with dlookup. Appears to load when using the file name. But I now get an error at nodes.add when trying to apply the image. Gives me the error "Object doesn't support this property or method"

Any suggestions ?
Dim istatus As New ImageList
    
'    Set imgx = istatus.ListImages.Add(, 1, LoadPicture(DLookup("ImageObj", "tlkp_Images", "ImageID = 1")))
    Set imgx = istatus.ListImages.Add(, 2, LoadPicture("C:\PP_projectmgr\closed.bmp"))
 
'....Node refence later in the code...
Set nodParent = tvwTree.Nodes.Add(, , "a" & !fldProjectIndexNo, !fldProject, imgx(2))

Open in new window

Microsoft Access

Avatar of undefined
Last Comment
Thirt

8/22/2022 - Mon
ASKER
Thirt

ok, found some more informaiton and lets see if I narrowed down the problem.

I didn't know there was an actual control called image list. I added one on my form called "imagelist0".

In that control, I was able to load the two bmp pictures I want to use and gave them the necessary key names.

When I double click on the Treeview control, I'm unable to assign the Imagelist0 as the imagelist. When I click the imagelist dropdown, my only option is "none".

So maybe I'm back to doing this in code? Since I'm calling a function in a module to populate the treeview, I have to refernce the full form name to the control.

But I just can't get the imagelist object defined, I keep getting the error 13: type mismatch


Public Sub dlg_PopulateTree(ByVal lngCompanyid As Long, ByVal intDisplayFilter As Integer)
    
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim strSQL As String
    Dim tvwTree As TreeView
    Dim nodParent As Node
    Dim nod As Node
    Dim bk As Variant
    Dim imglist As ImageList
 
Set cn = GetConnection
    Set rs = New ADODB.Recordset
    strSQL = _
      "SELECT tblProjectPartyRoles.fldprojectindexno, " & _
      "tblProjects.fldprojectnoconsultant ||'-' || Proj_Name as fldproject, " & _
      "tblProjects.fldprojectnoconsultant,  " & _
      "tblProjects.proj_name, tblOrganizations.fldpartyindexno " & _
      "FROM plus.tblProjectPartyRoles " & _
      "LEFT JOIN plus.tblOrganizations ON " & _
      "tblProjectPartyRoles.fldpartyindexno = tblOrganizations.fldpartyindexno " & _
      "INNER JOIN plus.tblProjects " & _
      "ON tblProjectPartyRoles.fldprojectindexno = tblProjects.fldprojectindexno " & _
      "WHERE tblProjects.fldpartof Is Null " & _
      "AND tblProjectPartyRoles.fldroletypeindexno=5 " & _
      "and tblOrganizations.fldpartyindexno = " & lngCompanyid & " " & _
      "ORDER BY tblProjects.fldprojectnoconsultant;"
 
rs.Open strSQL, cn, adOpenStatic
    
    Set tvwTree = Forms!fdlgFindProject!tvwProjectsTree.Object
    Set imglist = Forms!fdlgFindProject!ImageList0.Object  <<<<<<<<<<<<ERROR HERE
    
    Set tvwTree.ImageList = imglist
    
    tvwTree.Nodes.Clear
    
    gstrFieldID = "[fldProjectIndexNo]"
    gstrPartOf = "[fldPartOf]"
    With rs
        .MoveFirst
        Do Until .EOF
            Set nodParent = tvwTree.Nodes.Add(, , "a" & !fldProjectIndexNo, !fldProject, "open")
            
            bk = .Bookmark
            Call dlg_AddChildren(nodParent, cn, !fldProjectIndexNo, tvwTree)
            .Bookmark = bk
            
            .MoveNext
        Loop
    End With
    Set rs = Nothing

Open in new window

ASKER
Thirt

Think I found one problem. I was using the wrong activex imagelist control. I switch from version 6 to version 5(sp2) which appears to be from the same library as the treeview control. Now the imagelist "imagelist1" is showing in the dropdown and I can assign it to the treecontrol at the form level.

But when I populate the treeview, no errors, but no images.

So I put the code back in to define the objects and same problem.

Hopefully this narrows it down and I can stop talking to myself


    Set tvwTree = Forms!fdlgFindProject!tvwProjectsTree.Object
    Set ObjImages = Forms!fdlgFindProject!ImageList1.Object   <<<< no more error
    
    Set tvwTree.ImageList = ObjImages
    
    tvwTree.Nodes.Clear
    
    gstrFieldID = "[fldProjectIndexNo]"
    gstrPartOf = "[fldPartOf]"
    With rs
        .MoveFirst
        Do Until .EOF
            Set nodParent = tvwTree.Nodes.Add(, , "a" & !fldProjectIndexNo, !fldProject, "open")
            

Open in new window

ASKER CERTIFIED SOLUTION
Scott McDaniel (EE MVE )

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Thirt

I was actually...but I doubt correctly.

The value "open" is assigned as the key for the green check box in the Imagelist object on the form. So I changed it to your example.

Set nodParent = tvwTree.Nodes.Add(, , "a" & !fldProjectIndexNo, !fldProject, "open", tvwTree.ImageList(0))

And now get the error: Object doesn't support this property or method

The Intellisence is telling me the following:
Add([relative],[relationship],[text],[key],[image],[selectedimage]) as node

So i've been attempting to place the key "open" in the Image slot. The selected image slot has been confusing me. So I will try some differnt variations. But I'm still stuck.


Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
Thirt

I think the problem may be related to the funky way I'm trying to display the multiple levels of projects. Let me close this and define a better question.

I also found I got a better results when using the version 6 treeview and image list. I had to define the specific library to correct declare those objects...

 Dim tvwTree As MSComctlLib.TreeView
 Dim nodParent As MSComctlLib.Node