2

I have a TreeView with a ImageList populated in run time. This TreeView has only a root node and everything else is a direct child of that root node.

I have 2 problems:

1) My root node have a image, and I don't want.

//I tried to put -1, because this property has a default 0 (non-nullable int)
this.Nodes[0].ImageIndex = -1;
//But nothing happened.

2) The selected node always change the image to the index 0, it shouldn't

//Again, changing to -1 did nothing.
this.SelectedImageIndex = -1;

Example:

enter image description here

Reg Edit
  • 6,719
  • 1
  • 35
  • 46
Nicke Manarin
  • 3,026
  • 4
  • 37
  • 79
  • For your first issue, take a look here: http://stackoverflow.com/questions/261660/how-do-i-set-an-image-for-some-but-not-all-nodes-in-a-treeview It looks like an image is required for all nodes if you set it, looking at the setter it sets the value to 0 if it's -1 and throws an index out of bounds exception if it's less than that. You might be able to get your desired functionality through a messy hack, but the best bet would be to create your own UserControl – Saggio Jun 26 '14 at 19:58
  • Setting the index to `-1` before setting to something else will not throw a exception. But thanks. Maybe it's time for a own user control. – Nicke Manarin Jun 26 '14 at 22:21
  • setting it to `-1` works because the setter will set the value to `0` but if you set it to something else e.g. `-2` it will throw an exception. A UserControl would be the cleanest way, but looking at some of the other answers in the question I posted above you might be able to achieve what you're looking for. Take a look at the answer user1887120 posted – Saggio Jun 27 '14 at 12:38

1 Answers1

1

Get a blank .ico file (You can use this one :http://knowledgebase.twocoders.de/wp-content/uploads/2010/10/blank.ico) and add it to your image list. Set the image to the index of the blank.ico. The end result should will be a list view node without an icon. Here is an example of what it looks like:

This is a picture

Aelphaeis
  • 2,593
  • 3
  • 24
  • 42