|
-
Nov 24th, 2007, 11:43 PM
#1
Thread Starter
Lively Member
[RESOLVED] ListBox error using SelectedIndex
I'm having a problem with setting a ListBox's SelectedIndex from a sub.
I fill the ListBox with 8 items during Form_Load(). Once it's loaded, I select the index for the listing I want selected:
ListBox1.SelectedIndex = MyIndex, with MyIndex being an integer from 0-7.
Everything is fine until I try and change the selected index from any sub I create using the same code: ListBox1.SelectedIndex = MyIndex. When I do, I get this error:
ArgumentOutOfRangeException was unhandled
InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.
I doesn't matter if I use any value of 0 to 7, I get the same error. If I use -1, then it's fine; no selection.
What's weirding me out is that I can run the exact line of code from a button's Click event and it will work.
What am I missing?
Last edited by AlphaScorpious; Nov 25th, 2007 at 12:08 AM.
Reason: Came face to face with my own stupidity
-
Nov 25th, 2007, 12:11 AM
#2
Thread Starter
Lively Member
Re: [RESOLVED] ListBox error using SelectedIndex
So after spending hours trying to figure this out, I went to the old tried and true method of pulling my head out of my backside. Wow! I could actually I see my code now and realized that I was calling that sub in my Form_Load() BEFORE I had even populated the ListBox.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|