The 'SelectedImageIndex intent allows you to display a different image when selected than what is set to βImageIndex" for a specific node. To save these two alignments, you must set them to the same value. This can be done at design time or programmatically depending on your needs.
For example, if the images never change, it is as simple as installing them at the same time when a new node is added to the TreeView:
int myCurrentImageIndex = 0; TreeNode node = myTreeView.Nodes.Add("new node!"); node.ImageIndex = node.SelectedImageIndex = myCurrentImageIndex;
However, if you change the value of ImageIndex for any reason after its initial creation (for example, a response to some user action), you must also change the value of SelectedImageIndex. Otherwise, they will become inconsistent.
int myNewImageIndex = 1; node.ImageIndex = node.SelectedImageIndex = myNewImageIndex;
(Note that itβs not enough to specify that they are the same in the AfterSelect event handler. This should be done anywhere in your code where ImageIndex changes.)
Ray vega
source share