The parameter g is a Graphics object that corresponds to the text drawing area of the cell identified by Row, Column. This does not necessarily correspond to the entire cell content area, for example, if you use a row picture in the cell.
In order for this event handler to be called, the cell itself must have been given a value, even if it is blank.
Is this last sentence actually still the case? Just now looking at my code which loads up my listbox, I observe that what it actually does is to write a RowTag and two CellTags in every row, and it doesn’t write e.g. a space in each column to force the event to occur.
The listbox functions exactly as I expect it to, with all the drawing being done in the PaintCellText event. This event must therefore be firing for all visible cells, but this appears to me to contradict the documentation.
I want the event to fire so it can look in the rowtag and celltags and decide what to put in the cells. And it does so. In some cells it puts a picture, and text in others. I use PaintCellBackground to indicate a selected row, and I have two different types of selected row, each with its own colour.
Well - if one of the Xojo gurus (or present or former engineer) warned against doing that for some good and well-explained reason, I’d look into it. But presently it works as expected and on all the three desktop platforms, too.
What I’d really like is an answer to my OP. Because if that sentence is now out of date (well, it contradicts my programming experience, anyway), then I’d create an Issue for a doc change.
With .AddRow “” you are already setting an empty string to the first column.
Do that with a listbox with two columns and you will see only the first column will show anything.
It has been working like that for a long time.
Could be, could be. Anyway, I’ll ask that the sentence either be removed, or clarified. I know that documentation is hard. I’ve written a lot in the past, and one wants it to be clear without being overly verbose.
What it’s trying to say is that unlike PaintCellBackground, this event only fires for cells in which you have added something, even if that’s an empty string.
In PaintCellBackground you would need to check whether the row and column values are within list bounds, but in PaintCellText they will always be.
PaintCellBackground behaves the way it does so that something like an AlternatingList can draw rows that haven’t been added yet.
Oh, you’re right.
And if you happen to assign even an empty string, like the code below, the event suddenly fire for the additional column:
for i as Integer=1 to 10
me.AddRow ""
me.CellTextAt(me.LastAddedRowIndex,1)="" //Empty string so the paint event fires for that column
next
It rather looks like “not assigned” is not the same as “empty” or “ ” (space), the two latter being treated equally.
That’s a good point. But are you sure PaintCellText events for empty rows (added using ListBox.AddRow “”) did fire in far earlier Xojo (RealStudio) versions (e.g. ten years ago)? I seem to recall the need to handle these specifically, because CellTextPaint (the API1 version, at that time) wouldn’t execute for rows with empty strings.
Possibly, AddRow has been modified to never really add an empty string, in the meantime? (but that would break code…)