Results 1 to 3 of 3

Thread: check list box, clearing and gettings selected items?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2011
    Posts
    132

    check list box, clearing and gettings selected items?

    hmm i can't seem to figure out how to get the selected items from a check list box...

    i have 7 items in it, need to see which ones are selected...

    and how to clear the checks from the list box
    Last edited by StevenA; May 12th, 2011 at 08:33 PM.

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

    Re: check list box, clearing and gettings selected items?

    First up, "selected" and "checked" are two different things when talking about a CheckedListBox, as it is actually called. "Selected" has the same meaning as in a regular ListBox and "checked" means exactly what you'd expect.

    As always, your first port of call should be the documentation. Have you read the MSDN documentation for the CheckedListBox class? If not, why not? If you want to know how something works then the instructions that came with it should always be the first place you look. Being a beginner is more reason to read the documentation, not less. You may not always find what you're looking for and you may not always understand what you find but, the more often you do it, the better you will get at it.

    Had you read the documentation then you'd know that a CheckedListBox has a SelectedItems property and a CheckedItems property. Both are collections so you can do with them as you would with any collection, e.g. loop through all items, get the item count an access items by 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
    New Member
    Join Date
    May 2011
    Posts
    8

    Re: check list box, clearing and gettings selected items?

    It is easy :

    here is an example for a list box contains 3 items "hi","hello" and "Fine":



    Dim x As Integer
    x = ListBox1.SelectedIndex
    If x = 0 Then
    MsgBox("Hi")
    ElseIf x = 1 Then
    MsgBox("Hello")
    ElseIf x = 2 Then
    MsgBox("Fine")
    End If

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