Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Multiple StateImageList

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wallace - 20 Mar 2008 05:07 GMT
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
Peter Duniho - 20 Mar 2008 07:19 GMT
> 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?

I don't think so.

> Else someother way to accomplish this?

You can set the TreeView.DrawMode property to OwnerDrawAll, and handle the  
node drawing event, so that you can draw whatever images you want for the  
node.

Pete
Marc Gravell - 20 Mar 2008 09:05 GMT
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
Peter Duniho - 20 Mar 2008 17:47 GMT
> Another option; rather than tying to draw everything, perhaps just use
> different combinations of images to represent the different states.

True.  It can get out of hand if you're talking a lot of different  
possibilities, but assuming the actual possible combinations are  
relatively few and they can all be represented in a single image (I seem  
to recall a size restriction on the Image in the ImageList, but don't  
remember the specifics off the top of my head), this is certainly one  
valid approach.

Pete
Gunjan Karun - 20 Mar 2008 21:03 GMT
> Hi,
>
[quoted text clipped - 6 lines]
> Thanks,
> Prince

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

Regards
Prateek Raman
vvnraman - 21 Mar 2008 15:59 GMT
> Hi,
>
[quoted text clipped - 6 lines]
> 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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.