I am getting an out of bounds exception on a ListBox while getting the RowTagAt in the SelectionChanged Event.
I have two listboxes: Parent and Child. When I select a row in the parent I remove all the rows in the child and repopulate it with the appropriate child records.
Here is the code in the ParentListBox.SelectionChanged Event:
Var rs As RowSet
lbChild.RemoveAllRows()
rs = childrenByParent(lbParentList.RowTagAt(lbParentList.SelectedRowIndex).IntegerValue)
If rs <> Nil Then
for each row as DatabaseRow in rs
lbChild.AddRow row.Column("child_nm").StringValue
lbChild.RowTagAt(lbChild.LastAddedRowIndex)= row.Column("child_id").IntegerValue
Next
End If
In the Child Listbox the problematic code in the SelectionChange event is:
This works fine the first time I select a Parent and then Child record.
But when I select a new Parent / Child combination that is when I get the error.
Any ideas where I am going awry?
Just for clarity, this -1 thing has always been true. In the old framework, ListIndex would also be -1 if there was no selection and you would also get OutOfBoundsExceptions when trying to access rows or rowtags.
@MarkusR I am using the RowTag to store the Primary Key for the record that is being selected so enumerations are not optimal for me in this situation, but I will absolutely keep that in mind!