WebListbox.CellCheckBoxValueAt gives KeyNotFound Exception

I have a web listbox with checkboxes to enable a user’s security groups.

I set the checkbox column before any data is loaded:

Me.ColumnTypeAt(Integer(ColIndex.Include)) = WebListBox.CellTypes.CheckBox

The listbox is loaded with all the security groups first, then this code is used to set the checkboxes for the user’s current groups (I broke some things out while trying to isolate the exception):

For row = 0 To Me.LastRowIndex
group = Me.CellTextAt(row, colGroup)
inGroup = user.InSecGroup(group)
Me.CellCheckBoxValueAt(row, colCBx) = inGroup
Next

It executes for the first row, but I am getting a KeyNotFound exception in CellCheckBoxValueAt for the second row. I did find a little info about this where the KeyNotFound can raise when the CellType is not set properly, but ColumnTypeAt should have taken care of all the rows, right?

If you can create a small sample project that shows the problem, someone can take a look.
Is hard (for me) to give you an idea on what needs to be changed.
Are you using Xojo2025r2.1 or other version?
Your target is Linux, Windows or Mac?

I made a simple test project and was able to duplicate the problem, but as I was trying different versions of the code to see if I could get around the exception I noticed it only happened on the first False checkbox. This reminded me of a bug (and for the life of me I can’t find where I found it) where the checkbox cell has to be initialized to True or else the KeyNotFound exception is raised when trying to set it to False.

XOJO 2025r1.1, Target Mac

I ended up creating a “simple” list control for one of my projects using webhtmlviewer to make checkable lists. WebListBox is just overkill for this in my opinion.

It sounds like they are using a dictionary to hold the list of checked rows, probably with the rows unique ids as keys, and then looking in that dictionary to see if a row is checked when you ask for it. The KeyNotFound exception would happen if they used Value without first doing HasKey or instead using Lookup. Either way, there’s no easy way to fix it unless you make your own system for keeping track of what’s checked.

Maybe this one that was marked as fixed for 2025r2:
#79031 - Setting initial value to a Weblistbox Checkbox to False raises KeyNotFoundException

1 Like