Home All Groups Group Topic Archive Search About

ListView and ImageList/ImageKey

Author
16 Jul 2006 9:36 PM
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)

Author
17 Jul 2006 5:13 AM
glen.verwey@gmail.com
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!

Archimed wrote:
Show quoteHide quote
> 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)
Author
17 Jul 2006 1:19 PM
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 ! )



glen.ver***@gmail.com wrote:
Show quoteHide quote
> 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!
>
> Archimed wrote:
> > 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)
Author
17 Jul 2006 2:49 PM
glen.verwey@gmail.com
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.



Archimed wrote:
Show quoteHide quote
> 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 ! )
>
>
>
> glen.ver***@gmail.com wrote:
> > 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!
> >
> > Archimed wrote:
> > > 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)
Author
22 Jul 2006 8:53 PM
Archimed
Thanks a lot ! That's works :)


glen.ver***@gmail.com wrote:
Show quoteHide quote
> 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.
>
>
>
> Archimed wrote:
> > 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 ! )
> >
> >
> >
> > glen.ver***@gmail.com wrote:
> > > 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!
> > >
> > > Archimed wrote:
> > > > 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)