469,578 Members | 1,702 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

ImageList Component -- baffling behavior

(using VS2005)

I want to add an icon to TreeView nodes.

1) To a new project (VB or C#) I add a sample TreeView with some sample nodes. I add
an ImageList component, and add one icon image. I set the TreeView ImageList
property to the ImageList component and observe the expected results in the TreeView
as displayed in the IDE. However, this simple example will not compile and run. It
throws an unhandled exception in the Form's designer code, both in VB and C#.

2) Remove the TreeView leaving the ImageList with one image. The example will still
not compile and run - has same exception.

The designer has tree lines of code for the ImageList:
this.imageList1.ImageStream =
((System.Windows.Forms.ImageListStreamer)(resource s.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(0, "folder_16.ico");

The exception occurs on the third line (SetKeyName), the exception being "Index out
of Range". Examining imageList1.Images properties at that point shows an image
count of 0 which explains the exception, but I do not know why the "count" is 0.
In VB, rather than using the ImageList component, I found that creating the ImageList
at runtime for the TreeView works as expected. Now in C# when I try this approach,
the icon in the treeview displays about only about 50% of the time when the form is
loaded, otherwise the icon is not being painted the rest of the times.

Spending a couple of hours on google turned up nothing.

Does anyone have any idea as to what might be going on here?
Thanks,

Gene
Mar 7 '07 #1
0 2249

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by MB | last post: by
reply views Thread by alex n | last post: by
2 posts views Thread by Bob C. | last post: by
2 posts views Thread by Xarky | last post: by
6 posts views Thread by Stephen Costanzo | last post: by
5 posts views Thread by Vittorio Pavesi | last post: by
6 posts views Thread by henrycortezwu | last post: by
2 posts views Thread by senfo | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.