Converting WebListBoxStyleRenderer back to Text? - TypeMismatchException

I have a search routine I use to search the contents of a ListBox for a Text match. I’ve been struggling to figure out why that routine has been giving me a TypeMismatchException for a specific WebListbox in an App I have been converting to Web2. After trying several things I discovered that the cell contents were being returned as a WebListBoxStyleRenderer object and not text. I can’t seem to find anything in the documentation or on the Forum on how to convert that cell’s contents as a WebListBoxStyleRenderer back to a string to examine what that text string contents is and compare it to what I am searching for.

I’m also stumped at how to recognize that the cell contents is a normal string vs a WebListBoxStyleRenderer. If one Cell in a WebListbox is a WebListBoxStyleRenderer then are all Cells? I can’t seem to read the contents of any cells in a WebListbox that has some that don’t contain Styled Text.

Var ls As String
If listbox1.CellTextAt(r,c) IsA WebListBoxStyleRenderer Then
  // Just skip it
Else
  ls = listbox1.CellTextAt(row,column)
End If

This gets me no match for a string that should get a match but works just fine if the listbox contains no cells with a WebListBoxStyleRenderer.

How do I get to a WebListBoxStyleRenderer contents?

If I assign the Cell contents to a Variant then I can see the contents in the debugger. Even though it looks like the contents is a Dictionary Xojo gives me an exception that a a WebListboxStyle renderer can’t be a Dictionary it gets an IlegalCastException

Capture1

Capture2

Capture3

Why not store the value in the CellTagAt and search for it there?

Just a thought

That is certainly a possible solution, but there ought to be a way to access the cell contents. I’d rather not work around the issue unless Xojo says its not currently possible. If that’s the case I’ll file an issue and do the workaround.

And I found the answer through trial and error. This really ought to be in the documentation.

Var ls As String
Var w As WebListBoxStyleRenderer
If listbox1.CellTextAt(row,col) IsA WebListBoxStyleRenderer Then
  w = listbox1.CellTextAt(row,col)
  ls = w.Value
Else
  ls = listbox1.CellTextAt(row,col)
End If

Sigh!

1 Like

I used to face the same error at first stages and found another workaround.
Follow the return parameter by CellTextAt which is variant by doc and act accordingly based on variant type (more flexibility):

Var ls as String, totalvalue as Currency
Var w as Variant = lst.CellTextAt(row,col)

select case w.type
case 0 // Nil 
case 9 // Object
case 6 // currency
  totalvalue = w.CurrencyValue
case 8, 37 // String, Text
  ls = w.StringValue
case ...
end select

Variant Type (scroll to Constants)

Aslan that doesn’t work when you have applied a WebListBoxStyleRenderer to a cell. The Cell is no longer a Variant but is in actuality a WebListBoxStyleRenderer.

That’s interesting. I’m using this technic for WebListBoxStyleRenderer in all my projects.
Anyway, its good to see you found your own way.

1 Like

Stubbornness: the reason we have nice things today.

I mean it as a compliment :slight_smile: