Draw to the right of the list title

Is there a way to write or draw in the rectangle to the right of the title, marked with the red circle?


You meant the place where there is nothing inside the ListBox, above the ScrollBar ?

If so, try to put a Canvas there…

I’ve managed to fill that with colour to match the rest of the header row. I’ll look to see what I did. And the ability to do that may depend on platform, too.

EDIT: In my HeaderContentPaint event handler, I fill the header cell with colour using FillRectangle(). I use the HeaderBackgroundPaint event handler to do - nothing at all, except Return True. On the Mac, this magically uses the same colour as my FillRectangle() calls in HeaderContentPaint to fill that odd bit above the scrollbar (I think it works this way on Win also but not on Linux).

If I have the HeaderBackgroundPaint event handler but with it containing no code at all, then that odd bit is untouched. Whether this is a bug or intentional behaviour I know not.

1 Like

Thanks Tim, it works on Mac and Win !


How are you putting the ‘3’ in that odd bit?

yes, in the HeaderBackgroundPaint, as Str(column)

Ah, so if the listbox has n columns one can address the nth header cell?

apparently yes, and I find it very useful

here my code in HeaderBackgroundPaint, the listbox has 3 columns

g.forecolor = &cD9FFA700
g.FillRectangle(1, 1, g.Width-2, g.Height-2)
g.forecolor = &c00000000
g.DrawText Str(column), g.Width-10, g.Height-5
return true

it’s like some other events (dragenter for exeample) where you must return true to be able to use another event (dropobject) if you don’t return anything the other event is never fired.

The Question string is wrongI understnd it as you want to draw something at the rightmost part of the ListBox, not draw some text right aligned in each header cell.
The provided image enforce this (mis-)understanding.

Thus my wrong answer above.


But in my case it’s only that extra bit above the scrollbar which is not drawn if the HeaderBackgroundPaint event has no code.

Also, I just did an experiment and found that:

  1. The HeaderBackgroundPaint event is called with the column number =n (i.e., the piece above the scrollbar)

  2. The HeaderContentPaint event is not called for that bit. The highest column number is (n-1).

This looks more like a bug, the way this control works is buggy…

(At least on windows) the Y position of the scrollbar is at the top of the control, so that ackward space doesnt really exists:


Another problem is that Xojo uses TWO canvases to draw the list, one for the header and another for the body. This causes a awfull effect when draging the horizontal scrollbar because the header and the body are not really moving at the same time.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.