|
1 | | -# How-to-set-the-images-for-treenodeadv-in-the-winforms-treeviewadv |
2 | | -This session describes how to set the images for treenodeadv in the winforms treeviewadv. |
| 1 | +# How to set the images for TreeNodeAdv in the WinForms TreeView |
| 2 | + |
| 3 | +This session describes how to set the images for [TreeNodeAdv](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Tools.Windows~Syncfusion.Windows.Forms.Tools.TreeNodeAdv.html) in the [WinForms TreeView](https://www.syncfusion.com/winforms-ui-controls/treeview) (TreeViewAdv). |
| 4 | + |
| 5 | +`TreeView` 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](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Tools.Windows~Syncfusion.Windows.Forms.Tools.TreeViewAdv~LeftImageList.html) and [RightImageList](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Tools.Windows~Syncfusion.Windows.Forms.Tools.TreeViewAdv~RightImageList.html). It is also possible to specify different images for the individual nodes by using the [LeftImageIndices](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.TreeNodeAdv.html#Syncfusion_Windows_Forms_Tools_TreeNodeAdv_LeftImageIndices) and [RightImageIndices](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.TreeNodeAdv.html#Syncfusion_Windows_Forms_Tools_TreeNodeAdv_RightImageIndices) properties in the `TreeNodeAdv`. |
| 6 | + |
| 7 | +``` csharp |
| 8 | +//Assigns image list to the TreeNodeAdv. |
| 9 | +this.treeViewAdv1.LeftImageList = this.imageList1; |
| 10 | +this.treeViewAdv1.RightImageList = this.imageList1; |
| 11 | + |
| 12 | +//Gets the Path of the node and AddSeparatorAtEnd property set to true. |
| 13 | +string path = e.Node.GetPath("\\"); |
| 14 | + |
| 15 | +//Gets an Array of Directories from the current directory path. |
| 16 | +ArrayList dirs = new ArrayList(Directory.GetDirectories(path)); |
| 17 | + |
| 18 | +//Adds the Directories as a node in the TreeViewAdv |
| 19 | +for (int i = 0; i < dirs.Count; i++) |
| 20 | +{ |
| 21 | + string dir = (string)dirs[i]; |
| 22 | + int lastIndex = dir.LastIndexOf("\\") + 1; |
| 23 | + TreeNodeAdv node = new TreeNodeAdv(dir.Substring(lastIndex)); |
| 24 | + e.Node.Nodes.Add(node); |
| 25 | + node.RightImageIndices = new int[] { 1 }; |
| 26 | +} |
| 27 | + |
| 28 | +//Sets the Left images for the TreeNodeAdv. |
| 29 | +foreach (TreeNodeAdv node in this.treeViewAdv1.Nodes[0].Nodes) |
| 30 | +{ |
| 31 | + node.LeftImageIndices = new int[] { 1 }; |
| 32 | + node.RightImageIndices = new int[] { -1 }; |
| 33 | +} |
| 34 | + |
| 35 | +//Sets the Right images for the TreeNodeAdv. |
| 36 | +foreach (TreeNodeAdv node in this.treeViewAdv1.Nodes[0].Nodes) |
| 37 | +{ |
| 38 | + node.RightImageIndices = new int[] { 1 }; |
| 39 | + node.LeftImageIndices = new int[] { -1 }; |
| 40 | +} |
| 41 | +``` |
0 commit comments