Avatar of Nasser Hamdan
Nasser HamdanFlag for United Arab Emirates asked on

TreeView node images not displayed

Hi All,

Am using treeview on my desktop application and i choosed some images to be displayed with the nodes from imageList. But it doesnt displayed at all ... is there special type of images that treeview should take ? such as .ico, .png ..etc ,,, also is there some property that i am missing?

.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
Nasser Hamdan

8/22/2022 - Mon

TreeView is able to work with any of the standard image formats accepted by ImageList. Once you set the imagelist property on the treeview each node should be able to set the index from that imagelist object to acquire it's images. There aren't any magic properties here. In fact, just the opposite it's harder to not show images for a treeview with a imagelist set.

Are you doing anything like custom draw or custom extended TreeNode class?

I hope u r adding the nodes to tree something like this
TreeView1.Nodes.Add , , , "TestImageItem", 1

where 1 is the image index
Nasser Hamdan

Okay here is my code ,, everything is ok as it seems !!

** Designer Code for image list :

            this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
            this.imageList1.Images.SetKeyName(0, "Folder.png");
            this.imageList1.Images.SetKeyName(1, "index.png");
            this.imageList1.Images.SetKeyName(2, "folder-blue.ico");

** Binding code for tree

            // Create a node for the TreeView control.
            TreeNode node;
            node = new TreeNode("File",0,0);

            // Add a tag to the node for identifying the node type.
            // This tag is used to identify the context menu that is associated with it.
            node.Tag = "TextFile";

            // Add the node to the TreeView control.

            node = new TreeNode("File1",1,1);
            node.Tag = "File";

            node = new TreeNode("File2",0,1);
            node.Tag = "File";

Is there something wrong with this??


All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

I cannot see you assigning the image list to the tree view control

Nasser Hamdan

This is the treeview designer code ,, i am assigning it :

            this.tvBatches.ContextMenuStrip = this.mnuTextFile;
            this.tvBatches.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tvBatches.ImageIndex = 2;
            this.tvBatches.ImageList = this.imageList1;
            this.tvBatches.LabelEdit = true;
            this.tvBatches.Location = new System.Drawing.Point(0, 0);
            this.tvBatches.Name = "tvBatches";
            this.tvBatches.SelectedImageIndex = 2;
            this.tvBatches.ShowLines = false;
            this.tvBatches.Size = new System.Drawing.Size(207, 693);
            this.tvBatches.TabIndex = 24;
            this.tvBatches.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tvBatches_MouseUp);
            this.tvBatches.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvBatches_NodeMouseClick);
Nasser Hamdan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Just out of curiosity what is the VisualStyle that you have set that produces such fun problems? Are you using WindowBlinds or something?

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Nasser Hamdan

in your application main method ,, you can enable visual style as :


This will convert the whole application style as windows Xp style ,, but out of curiosity what is the WindowsBlinds ?


I'm familiar with the Application.EnableVisualStyle(); function. It causes your application to aquire the visual style that has been applied by the user. I was trying to figure out what you had done to your system settings that the XP style didn't work. If you don't know what WindowBlinds is then that's not the issue. Google "WindowBlinds" made by stardock if you want to know more about it.
Nasser Hamdan

I think there is a well known issue with EnableVisualStyle and imageList ,, there some bug on this from microsoft ,, if you do some research on this you will find that lot of people face the same problem when enabling the visual style while using imagelist.

Also i am not using windows blind aftre i now know what is it.

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.