Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to assign multiple icons to different nodes and sub-nodes...?

What I have tried:

 static ImageList imageList;
        public static ImageList ImageList
        {
            get
            {
                if (imageList == null)
                {
                    imageList = new ImageList();
                    imageList.Images.Add(Image.FromFile("database.png"));
                    imageList.Images.Add(Image.FromFile("sql.jpg"));
                   // imageList.Images.Add(Image.FromFile("col.jpg"));
                }
                return imageList;
            }
        }
 private void Form1_Load(object sender, EventArgs e)
        {
            treeView1.ImageList = ImageList;
            treeView1.Nodes[0].ImageKey ="database.png";
            treeView1.Nodes[0].SelectedImageKey = "database.png";
            treeView1.Nodes[1].ImageKey = "sql.jpg";
            treeView1.Nodes[1].SelectedImageKey = "sql.jpg";

            treeView1.Nodes[0].Nodes[0].ImageKey = "Table.jpg";
            treeView1.Nodes[0].Nodes[0].SelectedImageKey = "Table.jpg";
            treeView1.Nodes[0].Nodes[1].Nodes[0].ImageKey = "col.jpg";
            treeView1.Nodes[0].Nodes[1].Nodes[0].SelectedImageKey = "col.jpg";
        }
Problem:-
Only single image is showing by every node of the treeView control....
Posted
Updated 23-Jul-20 1:14am

1 solution

You can't add multiple icons to a single node or subnode: they only support a single image, and it isn't "shared" into subnodes.
If you want it to look like two icons, you will have to produce individual icons that contain both of the ones you want. And that's gong to be complicated, because every image in the ImageList has to be the shown at the same size, so they will be "resized" to 32x32, or 64x64 and so on. It's going to look like crap, to be honest.

Or write your own TreeView control from scratch! :laugh:
 
Share this answer
 
Comments
Member 12712527 23-Jul-20 7:36am    
No not saying that, but single node of the same group will have one image and another node of the same group will have another image. And also the sub-node of node[0] will have one different image other than these nodes....
Member 12712527 23-Jul-20 7:57am    
Sir my answer...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900