Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello once again Im looking to add images to my treeview. I have seen some turtorials and what not (most examples in C#) I need some explaination with VB. I have added a imagelist and selected the pictures I wish to add to the root and folders/subfolders and then choose the unselect and selected icon pics to use also. When I click the ok button my treeview shows the newly added icons but I cannot build the program? it errors..... how do I get and set the images? is there any code that I need to use to point to the icon files im using or do I need to point to the index number some how?

can someone give me a small example of how to do this?

thank you in advance..
Posted
Comments
Marc A. Brown 8-Feb-11 15:03pm    
You say that you can't build the program because it errors... what's the error?

1 solution

I assume you're talking about System.Windows.Forms, but your should always indicate the library you use: WPF, ASP.NET, so don't blame me if I'm answering a wrong question. Was that so difficult to read Microsoft documentation? You will have to read it anyway, see below.

There are two sets of images for System.Windows.Forms; see properties ImageList, and StateImageList. These image lists represent a whole set or small images 16x16 to be shown at each note. You better always use all of them for all nodes or always one of them, but not modify your choice (don't allow the situation when you sometime show only normal image, another time both images). The images are selected during run-time using special indexing. See code samples here: http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.imagelist.aspx[^], and here http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.stateimagelist.aspx[^].

See documentation on TreeView class for more detail: http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx[^].

—SA
 
Share this answer
 
v2
Comments
fjdiewornncalwe 8-Feb-11 18:26pm    
+5. Nothing more needs to be said.
Sergey Alexandrovich Kryukov 8-Feb-11 18:38pm    
Thank you Marcus. I guess OP expected ready-to-use sample, not a guide into reading... :-)
--SA
Dale 2012 9-Feb-11 3:12am    
Ok I have done everything here and yes I have read the microsoft msdn but sometimes I do better with a straight answer and not by reading page after page for which can be explained in a few breif sentences. Any hoo I see the images in the treeview but still cannot load the program.... the errors i get are:

1) Error 1 Could not load file or assembly 'file:///C:/Users/user/Desktop/Updated Code/Treeview)/bin/Debug/Interop.Shell32.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format. Line 161, position 5. C:\Users\user\Desktop\Updated Code\Treeview)\Form1.resx 161 5 Virus Scanner With Treeview (Working!!!)

2)Error 2 Unable to open file 'C:\Users\Draco\Desktop\Updated Code\Treeview\obj\x86\Debug\Virus_Scanner_With_Treeview__Working____.form1.resources': The system cannot find the file specified.

3)Error 3 Unable to open file 'C:\Users\Draco\Desktop\Updated Code\Treeview)\obj\x86\Debug\Virus_Scanner_With_Treeview__Working____.Resources.resources': The system cannot find the file specified.

3) same as Number 2 but different file cannot be found?

I have added them to the resources and also checked the folder and they are indeed there. What am I missing?
Dale 2012 9-Feb-11 5:19am    
Problem Solved!!!!!!!! I was doing everything correctly from the get go.... The error was caused by unused refrences. I cleared them and everything loads up smoothly.. Thank you for the reply!

take care have a nice day!
Sergey Alexandrovich Kryukov 9-Feb-11 15:56pm    
Thank you for reporting back.
Will you formally accept my answer? (Because I know it is correct.)
Thank you.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900