getting the selected items of a checklistbox into a tring array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hmznzr
    New Member
    • Dec 2008
    • 4

    getting the selected items of a checklistbox into a tring array

    i have a check list box. i am displaying the course names in that. user can check the courses they want to follow. they are allowed to select maximum of three courses. how can i get the checked course names into a string variable array.

    i am planning to update my database by using those string array variables.

    plzzz plzzzzzzz help me o this
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You want to use implement code that handles the CheckedListBox' s ItemCheck event. Here you can check how many courses the user has selected:

    [code=vbnet]
    Private Sub checkedListBox1 _ItemCheck(send er As Object, _
    e As ItemCheckEventA rgs) Handles checkedListBox1 .ItemCheck

    If e.NewValue = CheckState.Unch ecked Then
    If checkedListBox1 .CheckedItems.C ount < 3 Then
    checkedListBox1 .Enabled = True
    Else
    checkedListBox1 .Enabled = False
    End If
    Else
    button2.Enabled = True
    End If
    End Sub 'checkedListBox 1_ItemCheck
    [/code]

    You can determine which items were selected using the CheckedListBox' s CheckedItems property:

    [code=vbnet]
    For i = 0 To checkedListBox1 .CheckedItems.C ount - 1
    'insert code that builds string here.
    Next
    [/code]

    For more information on the CheckedListBox please see what MSDN has on the topic.

    -Frinny

    Comment

    • Xennex
      New Member
      • Jan 2009
      • 7

      #3
      Hmm.. Seems that the checked listbox is locked from editing once 3 items have been checked.. I guess if you use that code you may need something like a "clear selections" button to unlock it should changes need to be made in the selection. (^_^)

      Comment

      Working...