Multiple text lines in listbox header

Is it possible to have more than 1 text line in a listbox header column ?

instaed of ‘Date Created’
I would like to have in 1 header column displayed

  1. line: ‘Date’
  2. line: ‘Created’

since we can change listbox header height, we should be able to display multiple lines in a listbox header column …

Yeah, you can do this with the HeaderContentPaint-Event. You have to split the lines by yourself.

thanks Martin, I’ll try it

If you’ve got Xojo 2020r1 or better, refer to this Xojo Blog article (" Customize Your ListBox Headers"). You can find it at AFAIK, any version prior to 2020r1 doesn’t offer you any easy solutions for multi-line headers.

However, I would STRONGLY recommend that you look into investing in piDog Software’s DataView. It does bunches of things that the standard Xojo listbox doesn’t … including allowing the setting of Header Height. I find it infinitely easier to accomplish what I need using DataView (which is advertised as a “direct drop-in replacement” for the Xojo listbox … although I’ve found a few minor exceptions to that). And I think you’ll find DataView priced quite affordably. I’ve gotten to the point where I can’t do without it!

You can set the Header Height in Xojos Listbox using 2020+.

I have tried this in HeaderContentPaint

If column = 0 Then
g.DrawText ( “1.Line”, 0, 0 )
End If

Return True

but this displays nothing, header is empty

The location is wrong. You need to change the second 0 to the height of the font or more.

I know, Martin … that’s why I said “If you’ve got Xojo 2020r1 or better, refer to this Xojo Blog article” … but thanks anyways!

1 Like

That works, text displayed but is hard to read, almost the same colour as background

had to set the text colour

how can I center the text ?

Check out DrawingColor:

For centering you need to know the StringWidth:

Private Function getStringWidth(theString as String) as Integer
  dim thePicture as new Picture(500, 100, 32)
  thePicture.Graphics.FontSize = NSFontMBS.SystemFontSize
  Return thePicture.Graphics.TextWidth(theString)
End Function

Then you can calculate where to draw the text.

Drawing multiline code centered is a bit more work.

thank’s Beatrix,

I though it should be easy, now it turns out to be complicated, I will stay with my own listbox header object.

many thanks

1 Like