Back to Devexpress

TreeListNode.StateImageIndex Property

windowsforms-devexpress-dot-xtratreelist-dot-nodes-dot-treelistnode-9290fe99.md

latest8.3 KB
Original Source

TreeListNode.StateImageIndex Property

Gets or sets the index of the node’s state image from the TreeList.StateImageList collection.

Namespace : DevExpress.XtraTreeList.Nodes

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

csharp
[DefaultValue(-1)]
[DXCategory("Appearance")]
[ImageList("StateImageList")]
public virtual int StateImageIndex { get; set; }
vb
<DefaultValue(-1)>
<DXCategory("Appearance")>
<ImageList("StateImageList")>
Public Overridable Property StateImageIndex As Integer

Property Value

TypeDefaultDescription
Int32-1

An integer value that specifies the node’s state image index.

|

Remarks

Nodes can display the following icons:

  • Select Image - two icons that automatically switch when a node gets / loses the focus.
  • State Image - any custom icon.

State Image

State image: Specify image source

The TreeList.StateImageList property specifies an ordered (indexed) collection that stores images. You can use the following image collections:

State image: Assign images to nodes

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.

State image: Respond to clicks

The TreeList.RowStateImageClick event fires when a state image is clicked.

Example

The code below shows how to assign select and state images to nodes.

csharp
using DevExpress.XtraTreeList.Nodes;

// Data source for select (left) images.
treeList1.SelectImageList = imageCollection1;
// Use the data source to assign select images to nodes.
// Data source fields do NOT allow you to specify
// two images that depend on the focus.
// This property has priority over the node's
// ImageIndex and SelectImageIndex properties.
treeList1.ImageIndexFieldName = "ImageIndex";
// Data source for state (right) images.
treeList1.StateImageList = imageCollection1;
// Use the Load event to assign images to nodes.
treeList1.Load += TreeList1_Load;

private void TreeList1_Load(object sender, EventArgs e) {
    foreach (TreeListNode node in treeList1.Nodes) {
        // The left image displayed when the node is NOT focused.
        node.ImageIndex = 0;
        // The left image displayed when the node is focused.
        node.SelectImageIndex = 1;
        // The right image that does not depend on the focus.
        node.StateImageIndex = 2;
    }
}
vb
Imports DevExpress.XtraTreeList.Nodes

' Data source for select (left) images.
treeList1.SelectImageList = imageCollection1
' Use the data source to assign select images to nodes.
' Data source fields do NOT allow you to specify
' two images that depend on the focus.
' This property has priority over the node's
' ImageIndex and SelectImageIndex properties.
treeList1.ImageIndexFieldName = "ImageIndex"
' Data source for state (right) images.
treeList1.StateImageList = imageCollection1
' Use the Load event to assign images to nodes.
AddHandler treeList1.Load, AddressOf TreeList1_Load

Private Sub TreeList1_Load(ByVal sender As Object, ByVal e As EventArgs)
    For Each node As TreeListNode In treeList1.Nodes
        ' The left image displayed when the node is NOT focused.
        node.ImageIndex = 0
        ' The left image displayed when the node is focused.
        node.SelectImageIndex = 1
        ' The right image that does not depend on the focus.
        node.StateImageIndex = 2
    Next node
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the StateImageIndex property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-treelist-dynamic-load-nodes-unbound-mode/CS/TreeList-UnboundMode-ViaBeforeExpandEvent/Form1.cs#L97

csharp
node = treeList1.AppendNode(new object[] { s, di.Name, "Folder", null }, pNode);
node.StateImageIndex = 0;
node.HasChildren = HasFiles(s);

winforms-treelist-create-file-manager-drag-drop-files-folders/CS/FileList/FileListHelper.cs#L100

csharp
node = Tree.AppendNode(new object[] { s, di.Name, "Folder", null, di }, pNode);
node.StateImageIndex = 0;
node.HasChildren = HasFiles(s);

winforms-treelist-dynamic-load-nodes-unbound-mode/VB/TreeList-UnboundMode-ViaBeforeExpandEvent/Form1.vb#L84

vb
node = treeList1.AppendNode(New Object() {s, di.Name, "Folder", Nothing}, pNode)
node.StateImageIndex = 0
node.HasChildren = HasFiles(s)

winforms-treelist-create-file-manager-drag-drop-files-folders/VB/FileList/FileListHelper.vb#L82

vb
node = Tree.AppendNode(New Object() {s, di.Name, "Folder", Nothing, di}, pNode)
node.StateImageIndex = 0
node.HasChildren = HasFiles(s)

See Also

Node Image

StateImageList

GetStateImage

CustomDrawNodeImages

RowImagesShowMode

TreeListNode Class

TreeListNode Members

DevExpress.XtraTreeList.Nodes Namespace