Xojo2024R2.1: WebListbox with DataSource - cell background color

I have the method ApplyCellStyle that changes background color of certain cells in certain rows in the WebListbox. This method was called from custom LineAdded event of the WebListbox in the old version of the app (Xojo2018) when using custom DbListbox class.

In Xojo2024R2.1 I have removed the custom DbListbox class since I want to use DataSource class. In the RowData method I can determine color code needed and write to Tag.

I need now to use this value with the line/colum number to change the cell background color by using custom ApplyCellStyle method.

I am not sure if I can do it from within DataSource.RowData method. How should I go about this?

Since nothing is ever easy, if I call the method ApplyCellStyle I get the runtime error:

So how do I change the background color of the cell after all?

Neither CellValueAt() nor CellTextAt() can be used, using these will result in runtime error.

Maybe this will help:


Edit: is a little old, so I’m not sure if that will work with latest Xojo.

1 Like

Well, if it is possible indeed to change background color of the cell inside WebListbox using DataSource then the question is how to do it. If I knew how to do it for one cell then I can figure out how to adapt it for my needs. Maybe Ricardo can give me a hint?

Did you read the thread I pointed out?

Did you try adding code there?

Using the sample that comes with Xojo, simple checking if first name is “Abdul” then use style background yellow, if not then green:
image

If you can’t figure it out, here is the added/changed code:

Code used
Var style As New WebStyle
style.BackgroundColor = Color.Yellow

Var style2 As New WebStyle
style2.BackgroundColor = Color.Green
Var firstname As String = rs.Column("FirstName").StringValue
If firstname = "Abdul" Then
  row.Value("FirstName") = New WebListBoxStyleRenderer(style, firstname)
Else
  row.Value("FirstName") = New WebListBoxStyleRenderer(style2, firstname)
End If
'row.Value("FirstName") = rs.Column("FirstName").StringValue

Hope this helps.

3 Likes

Thank you, I can put the color on the background of the cell, it is too easy :wink:
I didn’t know that the change to the cell has to be done through the “row.Value” substitution before “rows.Add(row)” occurs. I wish I could find material on the web about this and read before wasting the proverbial “bandwidth” on this forum, but then again, this falls into the “manual” section.

Anyway, Alberto, you have given me the right solution, thank you.

1 Like

You are welcome, I’m glad I was able to help.

I didn’t know either, but found Ricardo’s post and then I was able to create the sample above. Sorry if my last post feels harsh, but ‘my solution’ is in fact what Ricardo posted there.

We both learned something new.

1 Like