Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add image in treeView

Tags:

c#

TreeNode desktop = new TreeNode();
desktop.Text = "Desktop";
desktop.Tag = "Desktop";
Mycomputer.ImageIndex = 1;
Mycomputer.SelectedImageIndex = 1;
desktop.Nodes.Add("");
treeView1.Nodes.Add(desktop);

TreeNode Mycomputer = new TreeNode("My Computer");
Mycomputer.ImageIndex = 1;
Mycomputer.SelectedImageIndex = 1;
treeView1.Nodes.Add(Mycomputer);

I am using the ImageIndex property but where is the image?

How do I choose my image and from where?

like image 871
ashish Avatar asked Aug 28 '10 14:08

ashish


1 Answers

For ImageIndex to have any meaning, your tree view should have an ImageList assigned. The ImageIndex property refers to the index within the image list of the image you want to present.

You can create an ImageList manually, or via the designer. This example demonstrates a method of creating and assigning an ImageList manually:

http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.imagelist.aspx

For me, I just pop open the designer, select the tree view, find the ImageList property in the property editor, and click it to launch a popup window that allows me to select and import a set of resources that become the image list.

Here are some screenshots of the process:

The ImageList component can be dragged onto your form from the toolbox.

Screen01

It has an Images collection among its properties.

Screen02

With the image list on the form, you can select it for the ImageList property on your tree view.

Screen03

I hope that helps fill some of the gaps.

Good luck!

like image 129
kbrimington Avatar answered Sep 18 '22 19:09

kbrimington