Results 1 to 2 of 2

Thread: [RESOLVED] ListBox error using SelectedIndex

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    74

    [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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width