Articles in this section

How to set the images for treeview nodes in the WinForms TreeViewAdv?

In WinForms TreeViewAdv control can be customized with images to the Left or Right side of its TreeNodeAdv. The images can be set on the Left or Right by using the properties LeftImageList and RightImageList. It is also possible to specify different images for the individual nodes by using the LeftImageIndices and RightImageIndices properties in the TreeNodeAdv.


C#

//Assigns image list to the TreeNodeAdv.
this.treeViewAdv1.LeftImageList = this.imageList1;
this.treeViewAdv1.RightImageList = this.imageList1;
 
//Gets the Path of the node and AddSeparatorAtEnd property set to true.
string path = e.Node.GetPath("\\");
 
//Gets an Array of Directories from the current directory path.
ArrayList dirs = new ArrayList(Directory.GetDirectories(path));
 
//Adds the Directories as a node in the TreeViewAdv
for (int i = 0; i < dirs.Count; i++)
{
    string dir = (string)dirs[i];
    int lastIndex = dir.LastIndexOf("\\") + 1;
    TreeNodeAdv node = new TreeNodeAdv(dir.Substring(lastIndex));
    e.Node.Nodes.Add(node);
    node.RightImageIndices = new int[] { 1 };
}
 
//Sets the Left images for the TreeNodeAdv.
foreach (TreeNodeAdv node in this.treeViewAdv1.Nodes[0].Nodes)
{
    node.LeftImageIndices = new int[] { 1 };
    node.RightImageIndices = new int[] { -1 };
}
 
//Sets the Right images for the TreeNodeAdv.
foreach (TreeNodeAdv node in this.treeViewAdv1.Nodes[0].Nodes)
{
    node.RightImageIndices = new int[] { 1 };
    node.LeftImageIndices = new int[] { -1 };
}

VB.Net

' Assigns image list to the TreeNodeAdv.
Me.treeViewAdv1.LeftImageList = Me.imageList1
Me.treeViewAdv1.RightImageList = Me.imageList1

' Gets the Path of the node and AddSeparatorAtEnd property set to true.
Dim path As String = e.Node.GetPath("\")

' Gets an Array of Directories from the current directory path.
Dim dirs As New ArrayList(Directory.GetDirectories(path))

' Adds the Directories as a node in the TreeViewAdv.
For i As Integer = 0 To dirs.Count - 1
    Dim dir As String = CStr(dirs(i))
    Dim lastIndex As Integer = dir.LastIndexOf("\") + 1
    Dim node As New TreeNodeAdv(dir.Substring(lastIndex))
    e.Node.Nodes.Add(node)
    node.RightImageIndices = New Integer() { 1 }
Next i

' Sets the Left images for the TreeNodeAdv.
For Each node As TreeNodeAdv In Me.treeViewAdv1.Nodes(0).Nodes
    node.LeftImageIndices = New Integer() { 1 }
    node.RightImageIndices = New Integer() { -1 }
Next node

' Sets the Right images for the TreeNodeAdv.
For Each node As TreeNodeAdv In Me.treeViewAdv1.Nodes(0).Nodes
    node.RightImageIndices = New Integer() { 1 }
    node.LeftImageIndices = New Integer() { -1 }
Next node

Images aligned left side of the TreeNodeAdv

 
  Figure 1:
Images aligned on the left side of the TreeNodeAdv

  

Images aligned right side of the TreeNodeAdv


 Figure 2: Images aligned right side of the TreeNodeAdv


Take a moment to peruse the WinForms TreeViewAdv -  ImageCustomization documentation, to learn more about image customization with examples.


View sample in GitHub


 

Conclusion

 

I hope you enjoyed learning about how to set the images for nodes in the WinForms TreeViewAdv.

You can refer to our WinForms TreeViewAdv  feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms TreeViewAdv example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied