WebListBox Checkbox Questsion Xojo 2025 R1.1

Hello all,

I have this little bit of code that I found was erroring… I am trying to set the checkbox to either True or False depending on which record in the listbox has been selected - so selected rows are True, non-selected are False.

For i As Integer = 0 To Me.RowCount
  If Me.Selected(i) = True Then 
    Me.CellCheckBoxValueAt(i ,0 )=  True 
    
  ElseIf Me.Selected(i) = False Then 
    Me.CellCheckBoxValueAt( i, 0) = False
    
  End If
Next i

Reviewing it, it appears that, according to the docs, I am doing it incorrectly. The docs show

CellCheckboxValueAt(column As Integer, Assigns value As Boolean)

    Sets the checkbox value of a cell of a WebListBox based on the given column index.

However, the ID Shows this

WebListBox.CellCheckBoxValueAt(row As Integer, column As Integer, Assigns value As Boolean)

Note the difference is the IDE shows Row, Col, Value BUT the docs show no ROW, only Column and Value.

Which is it?

Thanks,
Tim

Can you provide the error that you are getting?
Are you using WebListbox with or without DataSource?

My guess is that you are looking at the documentation for WebListboxRowData (that describes a row that uses the DataSource interface, and that is why no row is used) and CellCheckBoxValueAt without DataSource (in the IDE) that needs row and column (and I can’t find in the documentation).

Hi Tim,

I don’t know about your doc/syntax question but I think your code is incorrect and could be simplified.

Listbox index is zero based so RowCount will be out of bounds.
And you could simplify.

For i As Integer = 0 To (Me.RowCount - 1)
  Me.CellCheckBoxValueAt(i,0) = Me.Selected(i)
Next

Just my two cents … :wink:

1 Like

That’s a documentation issue (I’ll create a bug report), the correct method signature is:

WebListBox.CellCheckBoxValueAt(row As Integer, column As Integer, Assigns value As Boolean)

So the code from @Olivier_Colard should work fine.

Only when using a WebDataSource, WebListBoxRowData.CellCheckboxValueAt doesn’t have a row parameter, as it’s already a row. Just the column and value will be required in that case.

Is the error KeyNotFoundException? Take a look at:
#79031 - Setting initial value to a Weblistbox Checkbox to False raises KeyNotFoundException

1 Like

Hi All

@Oliver - yes, I forgot that but it did not make any difference.

@AlbertoD - Yes, that is the error.

I’ll try a difference approach while waiting for the fix…

Thanks all!
Tim

There is information on the ticket of what you can do.
Basically set to true before set to false.

Hi All,

This code works. What I was trying to do is to change the check back to unchecked if the row is not selected.

For i As Integer = 0 To Me.RowCount -1
  If Me.CellCheckBoxValueAt(i ,0 )=  True And Me.Selected(i) = False Then 
    Me.CellCheckBoxValueAt( i, 0) = False
    
  ElseIf Me.Selected(i) = True Then 
    Me.CellCheckBoxValueAt(i ,0 )=  True 
    
  End If
Next i

Thanks for the help!
Tim

Sorry, I see that it is working now.