In this tutorial we will learn how can we easy draw a picture in REALbasic ListBox control and how can we get the text from double clicked row or column in this control. So run REALbasic and start reading. Watch it, learn it, enjoy it!
Add to your Window ListBox Control and set the DefaultRowHeight property value to 32. Next prepare a 32×32 picture (called tutspolis) and drag it to your Project Tab.

In code editor go to ListBox Sub Open () and insert this code:
1 2 3 4 5 6 7 8 9 10 | Dim i As Integer for i = 1 to 5 ListBox1.AddFolder "REALbasic City" ListBox1.Cell(Me.LastIndex, 1) = "F" ListBox1.AddFolder "REALbasic City 2" ListBox1.Cell(Me.LastIndex, 1) = "F" next Me.ColumnAlignmentOffset(0)= 35 |
In REALbasic code editor go to ListBox Function CellTextPaint () and use this code:
1 2 3 4 5 6 7 | if column = 0 then if Me.cell(row,1) = "F" then g.DrawPicture(tutspolis,2,2) else g.DrawString "Fake Line", 29,9 end if end if |
Using this code in the ListBox Sub DoubleClick () event you can get the string, number of the cell, row that was double-clicked.
1 2 3 4 5 6 | Dim row, column As Integer row=Me.RowFromXY(System.MouseX - Me.Left - Self.Left, System.MouseY - Me.Top - Self.Top) column=Me.ColumnFromXY(System.MouseX - Me.Left - Self.Left, System.MouseY - Me.Top - Self.Top) MsgBox "You double-clicked on "+ Me.list(row) |

Really its good article. This is one I am looking for. Saved my time. Thanks and keep rocking!!
A real time saver. Cheers. – Steve
Thank you Steve and Arjun for nice word!
Cool and very useful article.
Re: Drawing a graphic in ListBox
What if you wanted to have a dynamically loaded image?
I have a picture that loads at runtime, how can I get that picture painted in the cell ?
And if the user wants to change that picture with another during runtime?
Thanks again Jakub — JT
Remove the ListBox1.Cell function and in ListBox Function CellTextPaint () enter:
if column = 0 the
g.DrawPicture(game4,2,2)
end if