Wallace said:
Hi,
In a treeview, I want to display tree nodes with multiple state.
Like a node with two state like active/inactive and checkedin/
checkedout icon. Is it possible to do with multiple stateimagelist?
Else someother way to accomplish this?
Thanks in advance.
Thanks,
Prince
Hi Wallace
Its possible to use any number of StateImageList for your TreeView
control.
Make as many ImageList objects as you wish to have as
System.Drawing.ImageList imgList1 = new System.Drawing.ImageList();
System.Drawing.ImageList imgList2 = new System.Drawing.ImageList();
Now add some images you wish to use as the states of the TreeView
control
as resources. You can do this by opening the
<Project Name>\Properties\Resources.resx file and choosing to add
existing file.
Assume the files as Slow1, Fast1, Slow2, Fast2 (in your case they
should
be active, inactive, checkedin, checkedout). (It will probably be an
image file,
i.e. jpg or png or bmp. In my case its png, i.e. Slow1.png and so on)
Now add the images to the ImageList as
imgList1.Images.Add(<ProjectName>.Properties.Resources.Slow1);
imgList1.Images.Add(<ProjectName>.Properties.Resources.Fast1);
imgList2.Images.Add(<ProjectName>.Properties.Resources.Slow2);
imgList2.Images.Add(<ProjectName>.Properties.Resources.Fast2);
Now programmatically assign the imgList1 or imgList2 to the
StateImageList property of
TreeView control to changed the StateImageList being used.
I wrote a small program to test it out. There is a TreeView control
(with its checkboxes
property set to true) and two buttons to switch between the two
StateImageLists.
Here's the code
namespace MultipleImageList
{
public partial class Form1 : Form
{
private ImageList imgList1;
private ImageList imgList2;
public Form1()
{
InitializeComponent();
InitializeUserComponent();
}
private void InitializeUserComponent()
{
imgList1 = new ImageList();
imgList2 = new ImageList();
imgList1.Images.Add(MultipleImageList.Properties.Resources.Slow1);
imgList1.Images.Add(MultipleImageList.Properties.Resources.Fast1);
imgList2.Images.Add(MultipleImageList.Properties.Resources.Slow2);
imgList2.Images.Add(MultipleImageList.Properties.Resources.Fast2);
treeView1.StateImageList = imgList1;
}
private void button1_Click(object sender, EventArgs e)
{
treeView1.StateImageList = imgList1;
}
private void button2_Click(object sender, EventArgs e)
{
treeView1.StateImageList = imgList2;
}
}
}
Hope this helps
Prateek Raman