I’m just developing my first application in Xojo, and I can’t find out how can I put a text and a picture into a same ListBox control cell.
I mean the same kind of cell like one in the “Movie Draft SE” application:
It might be a trivial question, but I can not figure out.
I hope someone can help me out
Thank you in advance.
You’re going to want to do the graphic and text drawing yourself.
In the CellBackgroundPaint event, draw the picture to the Cell in the desired location:
Event CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean
Dim Myicon As Picture ' get a reference to the picture you want
' draw it flush on the right side of the cell
g.DrawPicture(MyIcon, g.Width - MyIcon.Width, 0, bishop.Width, bishop.Height)
This event fires before any text is drawn to the cell, so will appear “behind” any text that overlaps.
There are a couple of ways.
You can use
listbox.rowPicture if you only need a picture in the first cell and you aren’t concerned with how the picture is drawn.
If you need more manual control over the picture (i.e. to center it, or do other things when drawing it), you can draw it yourself in the
Can’t edit: the above code mentions “bishop” where it should use “MyIcon”.
Thank you Andrew and Marc for the for the fast answer.
It helps me lot.
I just made a quick demo, but it works perfectly:
The only inconvenience was, that the CellBackgroundPaint event fires when the ListBox appears and I have no Resultset yet.
So I made an array of Dictionaries from the Resultset before the ListBox control became visible.
Thanks again guys,