weblistbox with no row colors

This may seem weird, but I’ve got a reason:

Is there a way to set the row colors for a weblistbox to nothing, no color at all?

The idea is to only show actual rows in the listbox

In the Inpector, you can set the alternate row color to be the same as the primary row color. That is not no color, but at least it gives a uniform color for the whole listbox. I don’t think that it will work either, but you could also try to assign a style with a 0 opacity setting.

Yeah, that’s the problem. I want to set the unused but visible rows to no color. I can only assign a style to a used row.

Hello @John Scanlan

Create a WebStyle and add a background (color) property only. Set the color property to the color you wish to apply to the alternate rows in your WebListBox. In my example code below I have named my WebStyle “styleBgColorAlt” (you can name it anything you like, however please remember to alter your code for the name of your WebStyle).

Then in the Open and/or Shown event for your WebListBox, place the following code:

Option 1: solid background color for alternate (populated) rows…


Me.PrimaryRowColor = &cFFFFFF // white
Me.AlternateRowColor = &cFFFFFF // white

// option 1
// solid background color for alternate (populated) rows
For r As Integer = 0 To Me.RowCount - 1
  For c As Integer = 0 To Me.ColumnCount - 1
    If r Mod 2 = 0 Then
      Me.CellStyle(r, c) = styleBgColorAlt // apply style to alternate row
    Else
      Me.CellStyle(r, c) = Nil // apply no style
    End If
  Next
Next

or Option 2: solid background color for all (populated) rows…


Me.PrimaryRowColor = &cFFFFFF // white
Me.AlternateRowColor = &cFFFFFF // white

// option 2
// solid background color for all (populated) rows
For r As Integer = 0 To Me.RowCount - 1
  For c As Integer = 0 To Me.ColumnCount - 1
    Me.CellStyle(r, c) = styleBgColorAlt // apply style to all rows
  Next
Next

If my understanding of your aim is correct, Option 1 is the right approach.

I hope that helps.

Kind regards, Andrew

Thanks . . . What I want to do is have any unpopulated rows not show at all.

Hello John,

The code supplied above does hide the unused rows, insofar as they appear as white space beneath the last populated row. That white space only appears due to the height you have set for the WebListBox. So if you wish to eliminate the white space altogether, you can adjust the height of the control to reflect the current number of populated rows.

In the WebListBox’s Open and/or Shown event:

Dim iHeading As Integer
If Me.HasHeading = True Then
  iHeading = 1
Else
  iHeading = 0
End If

Me.Height = (Me.RowCount + iHeading) * (Me.RowHeight(0) + 6) 

// note: the minimum row height reports as 22, however I believe 28 has worked for me in the past in avoiding the loading of a vertical scrollbar.

Again, I hope that helps.

Kind regards, Andrew

thanks but I’m looking for no color so the unused rows show as the same color as the background window

Hello John,

Two points:

  1. if you wish the match the background color of any unused rows to the background color of your webpage then set the initial PrimaryRowColor and AlternateRowColor to match the color your webpage background - then style any rows containing data as per Options 1or 2 in my earlier post.

  2. if you wish to show an image or other object behind the WebListBox by making the rows/cells transparent, then I refer you to this previous post https://forum.xojo.com/54855-weblistbox.

I hope that helps.

Kind regards, Andrew

I have not tried this. But what if you set the cell’s opacity to transparent? I assume that it would show the color of the window behind it.

Edwin . . . do you have a way to set a cell’s opacity?

I have not tested this. But I assume that you could set the opacity of the listbox using a WebStyle.

Otherwise, you could change the styles using CSS. I bet there is a way to do that in the open event of the control or window.

Was worth a shot but the listbox opacity overrides the cell opacity.

I set the listbox opacity to 0 and a cell style opacity to 100. The cell was invisible.

That actually makes a sense since the cells are embedded within the

frame of the listbox