Wednesday 12 September 2018

Delphi - Add an icon to a Node in TTreeView


1. Add your tree view to the form.

2. Add an TImageList to the form.

3. Double click on the ImageList component and add some images in.

4. Go to the Properties of the TreeView > Drop down the 'Images' property and select the name of the ImageList you've added.


5. Now in your code, where you're populating the treeview, you can add in code to set an icon/image to each node by referncing the image index:

//This will set the image of the node when resting
MyNode.ImageIndex := 0;  

//This will set the image of node when selected
MyNode.SelectedIndex := 0;

The index number refers to the image in the IMageList. This is zero based so the first image would be 0, the second would 1 and so on...