Resolved adding images to multicolumn listview

ExEdzy

Active member
Joined
Nov 25, 2010
Messages
37
Programming Experience
3-5
Hey guys

My problem is this..
I have

* listview1 (with 3 columns)
* imagelist1 (with images)

i want to add files to cols and subcols, but..

VB.NET:
 Dim itm As ListViewItem
Dim str(3) As String
str(0) = "Text to col 1"
str(1) = "Text to col 2"
str(2) = "Text to col 3"
itm = New ListViewItem(str)
itm.ImageKey = 0
ListView1.Items.Add(itm)

this code works in every aspect it should, except, it wont add image in front of every line (in rows)..

but this code works..

VB.NET:
ListView1.Items.Add("text", 0)

and yes, i have added imagelist1 to smallimagelist properti in listview

How can i make it work? :(
 
Last edited:
You should turn on Option Strict, at least that would have given you the first indication you're doing something wrong here.
Have a look at the help page for the constructor you mentioned last: ListViewItem Constructor (String, Int32) (System.Windows.Forms)
What does the second parameter really refer to? Hint, it is not "ImageKey".
Now take a look at the properties for ListViewItem class: ListViewItem Properties (System.Windows.Forms)
There are two 'Image' properties in particular you should take a closer look at, and I think you know which two I mean by now. Also notice the type of these properties.
 
Hey man, tnx..

To others, i just changed "itm.ImageKey = 0" to " itm.ImageIndex = 0" in my code.

SOLVED

Peas.. (hi)
 
Back
Top