Display the RowTagAt(folderitem) of a Listbox

Hi,
I want to read the items of a Listbox (with Checkbox) to store in an Array, their path (previously saved in RowTagAt() as folderitem) of checked items.
But I have an OutOfBoundsException exception in the msgbox
What’s wrong with my code?

Var items() As FolderItem
for x as integer = 0 to Listbox1.RowCount - 1
  if Listbox1.CellCheckBoxStateAt(x,0) = DesktopCheckbox.VisualStates.Checked then 
    items.add(Listbox1.RowTagAt(x) )
    msgbox(items(x).ShellPath) <--- OutOfBoundsException!
  end
next

Thanks

The number of items in the items array are not the same as you have rows in the listbox. Try

msgbox(items(items.lastindex).ShellPath)

1 Like

You do not always add something to the items Array, while you increment to x count.
So you might end up in a situation where you try to access item(x) but the last index in this Array is lower than x.

If you need the items Array as big as the number of rows in your listbox, add

Else
  items.Add // (something), maybe Nil

to your If…End IF condition.

(Just what @Beatrix_Willius said, just in other words)