1). Add an ImageList control to your WinForm.
2). Fill the ImageList with the images / icons you want to change / display in response to what the user does at runtime using the TreeView, for example, expanding or collapsing nodes.
3). Assign "ImageList Control" to the "ImageList" Property in TreeView
At this point, you can make an initial pass over the TreeView, assuming it is full, by setting the Node.ImageIndex property to point to Image ... in the ImageList ... that you want to use for Node depending on whether it has children or something else.
4). For example, if a user extends Node, you can use the BeforeExpand TreeView event to change the Node image: like this: in this case we use the image index in ImageList:
private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e) { e.Node.ImageIndex = 3; }
5) You can also set the Node image using the ImageKey property, which is the string name Image
6) There can be many other possible Node image options: check: SelectedImageIndex and SelectedImageKey: you can change the Node of the image in the BeforeSelect, AfterSelect and BeforeExpand events, depending on the effect you are using.
source share