Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about using imagelist for treeview and listview

Status
Not open for further replies.

at51178

Technical User
Mar 25, 2002
587
US
I already have a form with the treeview control which is working with no problem I would like to use the imagelist to add some images to the treeview control.
ALthough I am new with both the treeview control and have no experience with the imagelist control I would like to know if I would be able to add more than one image to the treeview so if the parent node has image one next to is I would like to have the child node have image 2 next to it and the child below that have image 3 if that is possible.
I also have a question about the listview I would like to know how to create a listview in access and add a imagelist to it.
I have checked everywhere on the web for a webpage that could help me with no luck. So you can add a link or help me out in any way I would be much appreciated.
Thanks
 
The ImageList control is in the same library as the TreeView control. You just select the "ActiveX Controls" button at the bottom of the toolbox, wait for the list of controls, find "Microsoft Image List", and click it. Then you click on the form to draw the control.

The ImageList itself is invisible at run time, so it doesn't much matter how big you make it.

Next you have to load your images into the ImageList. First set the size property on the General tab to indicate what size your images are. Then click the Images tab and click Insert Picture to add each image form a graphics file. It's helpful to give each picture a mnemonic Key property to identify it, but you can use the Index property if you prefer.

To associate the ImageList with the TreeView, you open the TreeView properties sheet and select the ImageList control from the ImageList property dropdown list.

At run time, as you build your nodes, you set the node's Image property to either the index or the key of the associated image. Which image goes with which node is entirely up to you. You can also change the images later by changing the Image properties of the nodes.

Note: Your TreeView control's Style property must be one of the styles that includes a Picture, or the images will not be displayed.

Also, note that if you distribute your application, you must also distribute the library containing these controls (COMCTL32.OCX for the SP5 version; I'm not sure of the library name for SP6), and your installation process may have to register the library on the target computers. If you have Office Developer Edition (or the Developer Tools add-on), your license allows you to redistribute the library. On the other hand, if you don't have the ODE, you can't legally redistribute it with an Access application.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Thanks for responding

After staying up late last night I was able to figure out how to set up a listview in Access but I still can not figure out how set up an imagelist to either a treeview or a listview control this is what I came up with so far

Assuming my imagelist control is named"axImagelist" and the name of my key is "Key1"

Me.axImagelist.listimages.add , , Key1,??(<-Not sure what to put here)
 
Er, I think we've had a disconnect here.

Most of what I described above would be done in Design View. I can't think of any reason to set up an ImageList in code, as this excerpt implies you're doing, unless you're writing a wizard or giving your end users control over the appearance of your application.

Also, you may have the concept a little backward. An ImageList is like a picture album. you don't tell it which TreeView or ListView it display its pictures on, you tell the TreeView or ListView which ImageList to get its pictures from. You do this by setting the property named &quot;ImageList&quot;, in the TreeView or ListView control's property sheet.

Am I misunderstanding? When you said you wanted to &quot;set up an ImageList in Access&quot;, did you actually mean you wanted to create, load, and use the ImageList using VBA code, or did you mean (as I assumed) that you wanted to use an ImageList on your form?

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Well I did try to do that when I firt started to fool around with it. The name of my imagelist is called &quot;Imagelist&quot; I went to the Properties section of my Treeview control and clicked on the dropdown box and picked imagelist when I I opened up the form nothing happened
 
What about the next two paragraphs in my original post? Did you set the Node.Image properties? Did you select a TreeView style that includes pictures?

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Yes I did pick an image if you want I could send you an example of what I did.
 
Sorry, but I don't publish my email address on the web.

Instead, maybe you'd show the code you use to build the nodes. Also, please tell me how many images you loaded into the ImageList control, and what size they are.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Ok this is what I did

I created two tables the first table called &quot;tblDepartment&quot;
with two columns &quot;DepartmentID&quot; and &quot;Department&quot;

The second table I created was called &quot;tblCategory&quot;
with three Columns &quot;DepartmentID&quot; , &quot;CategoryID&quot;, and &quot;Category&quot;.

I then referenced the DAO 3.6 Library

I then created a form named &quot;frmMain&quot;.
In the form I inserted the Treeview control 6.0
I renamed the TreeView control to
&quot;axTreeView&quot;
I then added a ImageView control and then renamed it to &quot;axListView&quot;. I went to the properties of the listview control and picked custom under the other tab and proceeded to insert a picture in the imagelist control. I only inserted 1 picture.

I then double clicked on the treeview control and proceeded to click on the dropdown tab next to imagelist and selected the &quot;axImageList&quot;.

I then sent to the onload portion of the form and added this code.

Private Sub Form_Load()
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset(&quot;tblDepartment&quot;, dbOpenDynaset)

Do Until rs.EOF
Me!axTreeView.Nodes.Add , , rs!DepartmentID, rs!Department
rs.MoveNext
Loop
rs.Close

Set rs = db.OpenRecordset(&quot;tblCategory&quot;, dbOpenDynaset)
Do Until rs.EOF
Me!axTreeView.Nodes.Add rs!DepartmentID.Value, tvwChild, rs!CategoryID, rs!Category
rs.MoveNext
Loop
rs.Close

Set rs = Nothing
Set db = Nothing
End Sub

I then viewed the form and was not able to see any images in the TreeView control.
 
Ok, I see. Let me repeat a paragraph from my initial post:
&quot;At run time, as you build your nodes, you set the node's Image property to either the index or the key of the associated image. Which image goes with which node is entirely up to you. You can also change the images later by changing the Image properties of the nodes.&quot;

You didn't set the nodes' Image property.

Instead of Me!axTreeView.Nodes.Add, you should be doing something like:
Dim nod As Node
...
Set nod = Me!axTreeView.Nodes.Add ...
nod.Image = 1 ' index of the image to be displayed on this node

Give that a try and let me know.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
OK it worked I was able to see the image
but I quickly ran into another problem When I went to add another image to the imagelist and then added

Nod.image = 2 to my child node all I saw was the image that I just added to the imagelist on the top.

Did I do something wrong

and another problem that I see was that the image on the primary node was right on top of it and not to the left side is that because my image may be too big or is it always that way
 
Let me recommend that you study the help topics a bit. Admittedly, the TreeView control is pretty complex, but the ImageList isn't too bad, and you should at least familiarize yourself with the documentation. If you don't have the help file for some reason, you can look it up in MSDN.

In the mean time, you probably couldn't add another image to the ImageList because you have to unhook it from the TreeView to do that, as you will read in the help file.

And it may be that the awkward positioning is related to your image size, but since you keep ignoring my question about the size, I'm only guessing. It may, on the other hand, have to do with one of the TreeView properties that controls how long the leaders lines are. I don't remember the name of the property off the top of my head. Check the help file.

(Are you noticing a trend here? RTFM!)

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Well thanks for the help you did put me on the right track
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top