From Xojo Documentation
The parameter g is a Graphics object that corresponds to the content area of the cell identified by the parameters Row, Column. 0,0 is the upper left of the cell.
Returns a Boolean. True means the user has handled the background paint and no other processing is to be done with the background. In this case the user is responsible for all highlighting. False means the user wants the default background; this will overwrite your drawing on the row that needs to be highlighted as the row or column will be highlighted as appropriate (according to the platform and the hierarchical style).
CellBackgroundPaint fires for every visible row in a ListBox, regardless of whether there is an actual row there or not. This enables you to implement the background paint event for the entire ListBox in a consistent way. For example, to do alternating row colors. Because of this, you need to check whether the current row is less than RowCount when accessing the row, for example with the Cell method.
Before CellBackgroundPaint fires, some drawing may have taken place. It isn't safe to assume that the background of the cell is white or that the selection hasn't already been drawn. If you need the background to be clear, you need to clear the background yourself and then return True.
When drawing to graphics on Windows HiDPI with a fractional scale factor you may run into a situation that is referred to as a "pixel crack". The symptom is that your drawing does not fill the entire graphics area causing small gaps between the cells.
In order to avoid this you need to disable anti-aliasing when drawing on Windows in this situation. You can easily do this like so:
If row >= Me.RowCount Then Return False
g.AntiAlias = False
g.DrawingColor = &c000000
g.FillRectangle(0,0, g.Width, g.Height)
This code can be used to do alternate row highlighting:
This example paints the cell background red if the CellTag contains the string "Red":