TreeView for WinForms | ComponentOne
In This Topic
    Custom Button Images for Nodes
    In This Topic

    TreeView allows you to easily display custom button images for nodes by using an image list.

    Create an instance of the Systems.Windows.Forms.ImageList class and add images to the list by using the Add method with the Images collection of the list. Set this instance as the image list of TreeView by using the ImageList property of the C1TreeView class.

    To access the collection of images for a particular node, you need to use the Images property of C1TreeNode. And to add a specific image from the image list to a specific node, add the index of the image by using the Add method of System.Collections.ObjectModel with the Images property of C1TreeNode.

    To see the implementation, refer to the following code snippets.

    ' create an instance of ImageList
    Dim imageList As New ImageList()
    
    ' add images to the image list
    imageList.Images.Add(Image.FromFile("C:\Resources\1.png"))
    imageList.Images.Add(Image.FromFile("C:\Resources\2.png"))
    imageList.Images.Add(Image.FromFile("C:\Resources\3.png"))
    
    ' set the image list instance as the TreeView image list
    C1TreeView1.ImageList = imageList
    
    ' specify image indices for nodes
    C1TreeView1.Nodes(0).Images.Add(0)
    C1TreeView1.Nodes(1).Images.Add(1)
    C1TreeView1.Nodes(2).Images.Add(2)
    
    // create an instance of ImageList
    ImageList imageList = new ImageList();
    
    // add images to the image list
    imageList.Images.Add(Image.FromFile("C:\\Resources\\1.png"));
    imageList.Images.Add(Image.FromFile("C:\\Resources\\2.png"));
    imageList.Images.Add(Image.FromFile("C:\\Resources\\3.png"));
    
    // set the image list instance as the TreeView image list
    c1TreeView1.ImageList = imageList;
    
    // specify image indices for nodes
    c1TreeView1.Nodes[0].Images.Add(0);
    c1TreeView1.Nodes[1].Images.Add(1);
    c1TreeView1.Nodes[2].Images.Add(2);
    

    Custom images for nodes