As a list is being loaded with data, through code or maybe directly from DBKit, how can I change the color of a row or cell, or perform some calcuation. I’m really wanting to know how or where to put the code to do ‘something’ when a row is being displayed. At this point, I don’t care if it slows down the loading, I just need to figure out whre things are or how to do the,
If row < 0 or row > me.LastRowIndex then Return
If me.RowTagAt( row ) = True Then
g.DrawingColor = &cFF00FF
g.FillRectangle( 0, 0, g.Width, g.Height )
Return True
End If
And, finally, at the end of your process that loads your data, you can set that row’s tag to False to display the default colors.
One tip to speed up the loading, set your Listbox.Visible property to false before you begin loading and modifying rows, then set it back to True once the update is complete. It saves repeated painting operations until the very end.
It can look odd if populating the ListBox takes too long. Usually, disabling the vertical scrollbar while populating it is sufficient. If I recall correctly, Xojo has configured the framework so that the ListBox only draws the visible content in this scenario.
All I am really asking for if is there an even when a row is loaded when using the DBKit. It not using thast, then you just laod the rows through code. As far as changing colors or calculations, they are coming form a business rule collection I have sspecific to a role each users has. e.g. a user with the role of Admin may want to hiighlight a row or cell in red if the invoice is past due for 60 days. A different user with a different role may want to display past due invoice in yello. It’s just the even I am looking for. Once I have that I will do what needs to be done. An even using the DBKit, or no.?
In the ListBox’s paint events you can set colours for any cell, based on any logic you want. There are the following events, you can simply set a colour and allow xojo to carry on, or handle the drawing all on your own:
YES! That is a huge help. One more question as I become familiar with this, for the row that is being displayed, how can I read the contents from another cell in the current row that is being loaded?
CellTextAt( row, column ). But you can also have a RowTagAt or CellTagAt that can hold information in raw format so you don’t have to decode a text version of the cell. These don’t show in the interface but are very useful.
For example if a column is a date the cell will still contain text, but you could store the true DateTime object in the CellTag for the row. Then you can do maths like date subtraction etc, rather than having to convert the text back to a DateTime every time a paint event occurs. Equally, you could just load a result into the CellTag at load time. So as you load the data set a RowTag to True / False and simply check RowTagAt(…) = true set colour to red.