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?
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.
It has an Images collection among its properties.
With the image list on the form, you can select it for the ImageList property on your tree view.
I hope that helps fill some of the gaps.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With