Multiple StateImageList

  • Thread starter Thread starter Wallace
  • Start date Start date
W

Wallace

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
 
Another option; rather than tying to draw everything, perhaps just use
different combinations of images to represent the different states. I use
this approach, and rather than create lots of physical images (for every
combination) I build the image-list at runtime by stitching together the
component images as required against a composite key.

In particular, I use this to create a tri-state checked tree cross-joined
with support for a category glyph, cross-joined with loaded/unloaded (greyed
out - it is lazy-loading) - so a "checked, machine, loaded" might have an
image with "CML" in the key, where-as an "indeterminate, printer, unloaded"
might have "IPU" etc.

I can post code for creating the image list (stitching images together etc)
if you need. The hit-test code to check/uncheck (to simulate a tristate) is
trickier...

Marc
 
Hi,

In atreeview, 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 multiplestateimagelist?
Else someother way to accomplish this?
Thanks in advance.

Thanks,
Prince

Its completely possible.
I wrote a small program to test this.

Regards
Prateek Raman
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top