Listbox images

Is there an example of a listbox with a colum showing images ?

Just draw the image in the ListBox.CellBackgroundPaint event

well, this is ok if there is a static picture to show, but how to add rows and different pictures in each?
Each row has to hold a class which has an image.

This code don’t work:

[code]dim u as UnClass
if column = 0 then
un = unitClass (me.CellTag(row,column))

if un <> nil then
g.drawpicture (un.Image,0,0)
end if
end if
[/code]

Are your images sized appropriately for the listbox? You may need to scale them. Otherwise, you’re just displaying a small portion from the upper left corner of the image. I’ve been fooled by that before.

Maybe the example: Desktop/Controls/ListBox/SourceListExample could help

as Markus said[quote=442094:@Markus Winter]Just draw the image in the ListBox.CellBackgroundPaint event[/quote]
nothing says each cell has to have the same image…

you can also use RowPicture depending on you exact need

P.S. i think Tim is right but make your Rowheight 500 pixel to check whether the picture is really drawn or not.

Also set a breakpoint and follow the code in the debugger to see if un is nil or not.

Btw the picture doesn’t need to be in a different class, picture itself is a class.

You can stuff just the picture into the rowtag or celltag.

[quote=442096:@Enric Herrera]well, this is ok if there is a static picture to show, but how to add rows and different pictures in each?
Each row has to hold a class which has an image.

This code don’t work:

[code]dim u as UnClass
if column = 0 then
un = unitClass (me.CellTag(row,column))

if un <> nil then
g.drawpicture (un.Image,0,0)
end if
end if
[/code][/quote]

P.S. several things seem wrong with the code:

You dim u but use un - that should not even run

You say UnClass but cast to UnitClass ??? Again that should not run.

When I try to run this sample, it can’t find the images. The images are located in: C:\Program Files\Xojo\Xojo 2019r1.1\Example Projects\Desktop\Controls\ListBox\Icons
How do I reconcile that?

[quote=442124:@Peter Greulich]When I try to run this sample, it can’t find the images. The images are located in: C:\Program Files\Xojo\Xojo 2019r1.1\Example Projects\Desktop\Controls\ListBox\Icons
How do I reconcile that?[/quote]
Yes, I reported that as a bug <https://xojo.com/issue/56116>
What you can do is: on the warning window select all the files, then go to that directory and select one of the images, that will fix the issue.

Thank you

[quote=442126:@Alberto De Poo]Yes, I reported that as a bug <https://xojo.com/issue/56116>
What you can do is: on the warning window select all the files, then go to that directory and select one of the images, that will fix the issue.[/quote]

I did that and this is what I get:

And the 2 or 3 items in the list are unclickable.

The app is working (images besides Inbox, Gmail and iCloud). It is weird that nothing show on that list. On my mac the icons show next to their names on the left panel. Maybe a Windows issue?

[quote=442122:@Markus Winter]P.S. several things seem wrong with the code:

You dim u but use un - that should not even run

You say UnClass but cast to UnitClass ??? Again that should not run.[/quote]
you are right I did not copy the code to post here, I rewrite it quickly and make a lot of mistakes. Sorry

[quote=442120:@Markus Winter]Btw the picture doesn’t need to be in a different class, picture itself is a class.

You can stuff just the picture into the rowtag or celltag.[/quote]

The cell tag row holds a Class and the list columns have to show several properties of the class instance, one of them is an image.

But what happens if you follow that code in the debugger? There is a lot of noise and very little facts here …

Btw you are obviously not a complete beginner, so I guess you know that you can look at the un.image and see what is in there.

[quote=442167:@Markus Winter]But what happens if you follow that code in the debugger? There is a lot of noise and very little facts here …

Btw you are obviously not a complete beginner, so I guess you know that you can look at the un.image and see what is in there.[/quote]

[code]Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) Handles CellBackgroundPaint as Boolean

if column = 0 then
dim unit as UnitClass
unit = (me.CellTag(row,column)) // <----- Crash
if unit <> nil then
g.drawpicture (unit.Image,0,0)
end if
end if

//

End Function

[/code]

this is the code copied here, and where it crashes. (outOfBoundException)

From memory, I think you can get paint events for rows that don’t actually exist.
Check what the row parameter is as it might be -1 or > the number of rows you actually have.

[quote=442175:@Kevin Gale]From memory, I think you can get paint events for rows that don’t actually exist.
Check what the row parameter is as it might be -1 or > the number of rows you actually have.[/quote]
I get the crash upon opening the list, so it’s empty, if I add:
If me.listcount >0
to avoid trigger the function when the list is empty, I get the crash when I add a row.

I’m probably doing something wrong but I do not know what.