if recipeListBox.SelectedRowCount > 0 then
numSelected = recipeListBox.SelectedRowCount
for i as Integer = 1 to numSelected
var x as String = recipeListBox.CellValueAt(recipeListBox.SelectedRowIndex, 0)
recipeIds.Add recipeListBox.CellValueAt(recipeListBox.SelectedRowIndex, 0)
recipeListBox.Selected(recipeListBox.SelectedRowIndex) = False
end if

The block of code above is supposed to iterate through a number of rows and pass the key values to a print method. My understanding was that SelectedRowIndex would return the first selected row. This isn’t behaving as expected
On my list I selected 5 rows. On the first iteration of the loop it returned the first selected row, on the second it returned the 3rd and on the 3rd iteration it returned the 5th selected row. The other two iterations both returned the first row in the listbox which wasn’t selected at all.
I tried removing the Selected = False row but that always returned the first selected row.

What am I doing wrong?


Instead of deselecting as you go, try using Selected.

Thanks for that.
That’s how I was doing it. I thought that using SelectedRowIndex as shown in my code snippet would mean I didn’t have to examine every row in the listbox.
It’s easy enough to revert to the that.

Thanks again