PopupMenu madness

Two PopupMenus are driving me bonkers.

Their index is -1 on startup.

In the open event I fill the PopupMenu and then set the index to 0 (works fine as I see it in the debugger)

[code] // set initial value

if me.ListCount > 0 then // starts at 1 so there is at least one protease

// set the popup menu to the first Protease
me.ListIndex = 0  // starts at 0[/code]

Setting the index triggers the changed event where I check that the PopupMenu is filled and refer to the index

[code] if me.ListCount > 0 then // starts at 1 so make sure there is at least one protease (they could all have been deleted!)

if me.RowTag( me.Index ) <> NIL then[/code]

but now the index has a value of -2147483648 and I get an OutOfBoundsException (even though it has four entries with objects in the RowTag).

Why???

I’m seeing this both in RS2012R2.1 and Xojo 2014 R2 on MacOS S 10.9.4.

P.S. I thought

if me.ListCount > 0 then
might set the index to -2147483648 but commenting out the line does not change things. It seems just entering the change event sets the index to -2147483648.

why here you referring to Index?

if me.RowTag( me.Index ) <> NIL then

should not be me.ListIndex?

I check that the RowTag really contains an object before referring to that object:

if me.RowTag( me.Index ) <> NIL then // set the selected Protease which is stored in the RowTag ProteaseInDigest = Protease( me.RowTag( me.Index ) )

Sorry, stupid me. Index != ListIndex

Thanks Massimo.