Page 1 of 1

Listview Control

Posted: Saturday 6th November 2021 8:08pm
by cage
I have trying to use a Listview control but nothing I have found seems to display the picture in the list. Most of what I have found on the internet was written back in 2005. If anyone can help I would greatly appreciate it.

Re: Listview Control

Posted: Saturday 6th November 2021 11:45pm
by BruceSteers
This code works as expected adding an item to the ListView then changing the image....

Public Sub Form_Open()
  
  ListView1.Add("i1", "Item1", Picture["icon:/16/added"])
  ListView1["i1"].Selected = True

End


Public Sub Button1_Click()

  ListView1["i1"].Picture = Picture["icon:/16/bookmark"]
  

End

Public Sub Button2_Click()

  ListView1["i1"].Picture = Picture["icon:/16/agenda"]

End

Re: Listview Control

Posted: Saturday 6th November 2021 11:52pm
by BruceSteers
cage wrote: Saturday 6th November 2021 8:08pm I have trying to use a Listview control but nothing I have found seems to display the picture in the list. Most of what I have found on the internet was written back in 2005. If anyone can help I would greatly appreciate it.
PS.
I find the as-you-type Auto-complete text is much more up to date with help than the wiki.
that's how i found the ListView Items Picture property.
Like you i found nothing on the wiki :(

Re: Listview Control

Posted: Sunday 7th November 2021 1:43am
by cage
Thanks Bruce. I had to remove the icon/16/ to make it display the icon but really small. I take it only uses icon files and not png icons. I will do some more experiments with it.

Here is what I did to the code:
  ListView1.Add("i1", "First Item1", Picture["cabinet.ico"])
  ListView1.Add("i2", "Second Item2", Picture["Applauncher.ico"])
  ListView1["i1"].Selected = True
Image

I used Pinta image program to convert the png files to ico and to a size I wanted to try. Once again thank your for your help. It is greatly appreciated.

Re: Listview Control

Posted: Sunday 7th November 2021 9:40am
by BruceSteers
cage wrote: Sunday 7th November 2021 1:43am Thanks Bruce. I had to remove the icon/16/ to make it display the icon but really small. I take it only uses icon files and not png icons. I will do some more experiments with it.

Here is what I did to the code:
  ListView1.Add("i1", "First Item1", Picture["cabinet.ico"])
  ListView1.Add("i2", "Second Item2", Picture["Applauncher.ico"])
  ListView1["i1"].Selected = True
Image

I used Pinta image program to convert the png files to ico and to a size I wanted to try. Once again thank your for your help. It is greatly appreciated.
You're welcome :)
You should be able to use any image format that Picture.Load() supports with any path.

Using the path "icon:/" shows all the gambas png stock icons. (If you type icon:/ in the name field it will popup a list of all the size folders for required icon size) :)

you could do a quick resize to any desired fixed size using the Pictures Image property when loading it.

Picture["cabinet.ico"].Image.Stretch(32,32).Picture

Re: Listview Control

Posted: Sunday 7th November 2021 7:36pm
by cage
Thanks again Bruce, that did the trick.