The problem surely lies in the way VB.NET is handling array indices.
Obviously, in your .vb file there must be a
Option Base 1
directive.
This has the effect of indexing arrays from 1 to Count.
Whereas the
SelectedIndex
of a
ListBox
returns a value between 0 and (Count - 1) (which corresponds to
Option Base 0
in VB.NET).
You then have two alternatives :
- OR you set
Option Base 0
- OR you convert every index obtained by adding it 1
The former is probably the best one, as this will lead to a kind of consistency with array indices in your application.