ListBox Columns and Rows

I hate to ask such a seemingly simple question, especially when I’ve done what I’m trying to do in the past without problem. But I have a ListBox with 6 columns, and I’m trying to populate each column with data. As best as I can tell from the Docs, to populate the first column, I should be using “CellTagAt,” with a loop. For instance:

For i as Integer =  myArray.FirstIndex to myArray.LastIndex
  ListBox1.CellTagAt(0, i) = myArray(i)

But I’m getting an OutOfBounds Exception. I know a lot has changed in Xojo since I last did this but I can’t seem to find the correct way to do it now. Any help would be greatly appreciated. Thanks!

Hi Robert,

I can think of a couple of potential causes that would generate an OutOfBoundsException:

  1. Row 0 doesn’t exist. Use Listbox1.AddRow before your code
  2. MyArray has a greater number of members than there are columns

Also, if you are trying to display the data in the cells, you should be using Listbox.CellValueAt, rather than CelltagAt

Hope that helps!

1 Like

Thanks, Frank! After I posted the question, I realized that I hadn’t added a row yet, so that solved problem one.

Problem two was that “ListBox.CellValueAt” was giving me the error:

Type "DesktopListBox" has no member named "CellValueAt"

Happily, I found that “ListBox1.CellTextAt” did the trick.

Thanks again!

You can also populate new rows faster by putting everything on one line.

Instead of:

MyListbox.AddRow " "
MyListbox.Cell(MyListbox.LastIndex, 0) = w
MyListbox.Cell(MyListbox.LastIndex, 1) = x
MyListbox.Cell(MyListbox.LastIndex, 2) = y
MyListbox.Cell(MyListbox.LastIndex, 3) = z

You can do it like:

MyListbox.AddRow w, x, y, z

That does not work for MyListbox.AddRowAt however.

1 Like