Results 1 to 3 of 3

Thread: retrieving listbox data

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    12

    retrieving listbox data

    bassically i want pull the info out the list boxs so i can check if certain stuff has been selected.

    ive tryed stuff like.

    item = ListBox1.Items.Item(1)

    but get this error
    InvalidArgument=Value of '1' is not valid for 'index'. Parameter name: index

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: retrieving listbox data

    As for all .NET collections, the Items property of the ListBox is zero-based, so the first item is at index 0. If you want to get all items you can use a loop like so:
    vb.net Code:
    1. For Each item As Object In ListBox1.Items
    2.     MessageBox.Show(item.ToString())
    3. Next Item
    or:
    vb.net Code:
    1. For index As Integer = 0 To ListBox1.Count - 1 Step 1
    2.     MessageBox.Show(ListBox1.Items(index))
    3. Next index
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    12

    Re: retrieving listbox data

    thx, worked a treat

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