Jump to content

TreeView - multi icons

- - - - -

  • Please log in to reply
2 replies to this topic

#1
blm

blm

    Newbie

  • Validating
  • Pip
  • 2 posts
Hi!
I'm looking for a way to add multiple icons to the treeview item (for example 3). It's possible ?

#2
Jarryd

Jarryd

    Learning Programmer

  • Members
  • PipPipPip
  • 63 posts
It is possible, to do this you'll need to add some variables and system usages,

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

We will need to create an "ImageList" which will store all our images.

ImageList iList = new ImageList();

An ImageList is a supporting control that is typically used by other controls, such as a ListView but is exposed as a component to developers. We can use this component in our applications when we are building our own controls such as a photo gallery or an image rotator control.

Once that is declared, We can begin with the adding of the images to the lsit.

iList.Images.Add(new Icon("Image0.ico"));

iList.Images.Add(new Icon("Image1.ico"));

iList.Images.Add(new Icon("Image2.ico"));

// iList.Images.Add(new Icon("Image3.ico"));

treeView1.ImageList = iList ; 

Next we need to createa a Root Node,

TreeNode rootNode = treeView1.Nodes.Add("Root Node");

rootNode.ImageIndex = 0;

In computer science, a tree is a widely-used data structure that emulates a hierarchical tree structure with a set of linked nodes, The root node being the main structure.

Now we need to create some Child Nodes,

TreeNode child1 = rootNode.Nodes.Add("Child Node 1");

child1.ImageIndex = 1;

TreeNode child2 = rootNode.Nodes.Add("Child Node 2");

child2.ImageIndex = 1;

A child node or descendant node is a node in a tree data structure that is linked to by a parent node or root node. Thinking of the tree as a directed graph, node A is a child of node B if and only if node A is a sucessor node of B.

And finally we need to add some Sibling Nodes,

TreeNode child = child1.Nodes.Add("Sibling Node");

child.ImageIndex = 2;

child = chiListd1.Nodes.Add("Sibling Node 1");

child.ImageIndex = 2;

child = child1.Nodes.Add("Sibling Node 2");

child.ImageIndex = 2;


child = child2.Nodes.Add("Sibling Node");

childd.ImageIndex = 2;

child = child2.Nodes.Add("Sibling Node 1");

child.ImageIndex = 2;

child = child2.Nodes.Add("Sibling Node 2");

child.ImageIndex = 2;

The end result...

Posted Image
(The images are not mine, I found them in a tutorial a few years ago)

#3
blm

blm

    Newbie

  • Validating
  • Pip
  • 2 posts
I thinking about three icons associated to one element (node) of three.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users