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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Graphics for selected treenodes 1

Status
Not open for further replies.

golcarlad

Programmer
Nov 23, 2004
232
GB
Is there a way to show a little graphic next to a node in a tree view to show it as selected?
 
Yes. You have to use an ImageList.

- Add the image(s) you want to use to the ImageList.
- Assign the ImageList to the ImageList property of the TreeView.
- If your tree nodes are static (set at design time), you can set the ImageIndex and SelectedImageIndex properties of the node in the designer.
- If your tree nodes are dynamic (built at run time), you set those same properties in your code.
- If you only want an image when the node is selected, don't set the ImageIndex, just the SelectedImageIndex.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
Thats great - thanks for your help.
However when looking at the MSDN help - it says that the bug has been fixed in Net 2.0 - when you images dont show on treeviews if you have called EnableVisualStyles() - well Im running version 2 and the problem is still there - anyone else find this too.

MDSN reference:
 
How annoying - I got the images to work in the treeview and they look cool - but when I installed my code on the test machine - the images would not show - just had blank areas on the treeview!!!

Anyone know how to get around this? I have tried the DoEvents() solution after EnableVisualStyles() call, but to no avail - should I be embedding the bmp icons or something in some special way???

Any ideas much appreciated.
 
I haven't had this issue. Are you doing this on the web? The places where I've used this have all been WinForms apps. Maybe you need to make sure that the .resx file gets deployed with your application?

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
No these are WinForms apps. The bug/error appears intermittently between every rebuild/release of my code (hence the diffiuclty with nailing this!) - sometimes the icons show, sometimes not - and between release, the code to do with the treeview has not been altered.
 
Is the test machine using a different version of the .NET runtime than the dev machine?

---------------------------------------
A picture is worth 2,000 bytes.
---------------------------------------
 
Exactly the same version. In any case it occurs on the Dev machine too (intermittantly).
 
Exactly the same version. In any case it occurs on the Dev machine too (intermittantly).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top