Text and picture in a ListBox control cell

Hello,

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 :slight_smile:

Thank you in advance.
Istvan

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) 
  Return True
End Event

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 listbox.cellBackgroundPaint event.

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,
Istvan