(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