ListView and ImageList/ImageKey

A

Archimed

Hi,

I try to use an ImageList with a ListView but that don't work.

I make a ListView in VirtualMode with LargeIcon view.
I put the ImageList in the LargeImageList property.

I add a bitmap to the ImageList

When i want to see the item "icon" with the imagelist imageindex
property that work, but with the imagekey property that don't work

At the form load :
ListView1.VirtualListSize = 1

In the RetrieveVirtualItem event (use ImageIndex):
Dim item As New ListViewItem("test", 0)
e.Item = item

That work

In the RetrieveVirtualItem event (unse ImageKey) :
Dim str As String = "1.JPG"
Dim item As New ListViewItem("test", str)
e.Item = item

That don't work ! However ImageList1.Images.ContainsKey(str) = true !

Could you help me ?
I have forgotten something ?
Thanks

(excuse me, i don't speak English very well)
 
G

glen.verwey

Hi Archimed

Your problem is with the way you set the image index
<1> Dim str As String = "1.JPG"
<2> Dim item As New ListViewItem("test", str)
<3> e.Item = item

You can remove line <1> and change line <2> to this:
<2> Dim item as new ListViewItem("test", 0)

The second parameter for the ListViewItem constructor as image index
position of the item's icon within the associated ImageList.

Hope this helps!
 
A

Archimed

Hi,
Thanks for your reply

But i need to use the imagelist with ImageKey

The ListViewItem contain however this constructor :
.... New(ByVal text As String, ByVal imageKey As String)

I don't know why that don't work (ImageList1.Images.ContainsKey(str) =
True ! )
 
G

glen.verwey

Hi

Okay, I didn't see the constructor myself (it's good that they've added
it)...I am able to get it to work when not using the list view in
virtual mode but not while using VirtualMode. Very strange stuff!

Why not try the following as a workaround:

Dim str As String = "1.JPG"
Dim item As New ListViewItem("test",
ListView1.LargeImageList.Images.Key(str))

Of course this means you won't be able to change the View type as
easily (e.g. from LargeIcon to SmallIcon).

Sorry I couldn't help further.
 
A

Archimed

Thanks a lot ! That's works :)


Hi

Okay, I didn't see the constructor myself (it's good that they've added
it)...I am able to get it to work when not using the list view in
virtual mode but not while using VirtualMode. Very strange stuff!

Why not try the following as a workaround:

Dim str As String = "1.JPG"
Dim item As New ListViewItem("test",
ListView1.LargeImageList.Images.Key(str))

Of course this means you won't be able to change the View type as
easily (e.g. from LargeIcon to SmallIcon).

Sorry I couldn't help further.
 
Joined
Apr 15, 2009
Messages
1
Reaction score
0
C#

I want to add images on subitems of listview controls.
i put the imagelist1 on the LargeImageList property of listview Control...
can plz anyone figure it out using C# code.......
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top