windowsforms-devexpress-dot-xtratreelist-dot-treelist-2b1cb0d3.md
Allows you to assign state images to nodes.
Namespace : DevExpress.XtraTreeList
Assembly : DevExpress.XtraTreeList.v25.2.dll
NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList
public event GetStateImageEventHandler GetStateImage
Public Event GetStateImage As GetStateImageEventHandler
The GetStateImage event's data class is GetStateImageEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Node | Gets the current Tree List node. Inherited from NodeEventArgs. |
| NodeImageIndex |
Gets or sets the index of the node’s image in a source image list. When handling the TreeList.GetStateImage event, the source of images is specified by the TreeList.StateImageList property. When handling the TreeList.GetSelectImage event, the source of images is specified by the TreeList.SelectImageList property.
|
Nodes can display the following icons:
The TreeList.StateImageList property specifies an ordered (indexed) collection that stores images. You can use the following image collections:
To specify the index of the image displayed in a particular node, use the following properties and events:
the TreeListNode.StateImageIndex property — gets or sets the image index.
the TreeList.GetStateImage event — fires before a node is displayed and allows you to specify (override) the image index for the processed node.
If the index is out of range, no image is displayed.
The TreeList.RowStateImageClick event fires when a state image is clicked.
The code below shows how to display state images depending on data field values.
using DevExpress.XtraTreeList;
string currentGroupName;
private void treeList1_GetStateImage(object sender, GetStateImageEventArgs e) {
if(treeList.IsAutoFilterNode(e.Node))
return;
string[] groupNames = new string[] { "Administration", "Inventory", "Manufacturing", "Quality", "Research", "Sales" };
currentGroupName = (string)e.Node.GetValue("GroupName");
e.NodeImageIndex = Array.FindIndex(groupNames, new Predicate<string>(IsCurrentGroupName));
}
private bool IsCurrentGroupName(string groupName) {
if(currentGroupName != null)
return currentGroupName.Contains(groupName);
return false;
}
Imports DevExpress.XtraTreeList
Private currentGroupName As String
Private Sub treeList1_GetStateImage(ByVal sender As Object, ByVal e As GetStateImageEventArgs) Handles treeList.GetStateImage
If treeList.IsAutoFilterNode(e.Node) Then
Return
End If
Dim groupNames() As String = { "Administration", "Inventory", "Manufacturing", "Quality", "Research", "Sales" }
currentGroupName = DirectCast(e.Node.GetValue("GroupName"), String)
e.NodeImageIndex = Array.FindIndex(groupNames, New Predicate(Of String)(AddressOf IsCurrentGroupName))
End Sub
Private Function IsCurrentGroupName(ByVal groupName As String) As Boolean
If currentGroupName IsNot Nothing Then
Return currentGroupName.Contains(groupName)
End If
Return False
End Function
Note
Run the XtraTreeList demo for the complete example.
The code below shows how to display state images depending on the node check state.
using DevExpress.XtraTreeList;
ImageCollection collection = new ImageCollection();
collection.Images.AddRange(new Image[] { img, img2 });
treeList1.StateImageList = collection;
treeList1.GetStateImage += treeList1_GetStateImage;
private void treeList1_GetStateImage(object sender, GetStateImageEventArgs e) {
if (e.Node.Checked)
e.NodeImageIndex = 1;
else
e.NodeImageIndex = 0;
}
Imports DevExpress.XtraTreeList
Private collection As New ImageCollection()
collection.Images.AddRange(New Image() { img, img2 })
treeList1.StateImageList = collection
AddHandler treeList1.GetStateImage, AddressOf treeList1_GetStateImage
private void treeList1_GetStateImage(Object sender, GetStateImageEventArgs e)
If e.Node.Checked Then
e.NodeImageIndex = 1
Else
e.NodeImageIndex = 0
End If
See Also