Get selected items in a Checkbox List in vb.net

The following example shows how to get selected items from CheckedListBox control in windows application using vb.net.

In this example we will bind all checked items of checkedlistbox control into Listbox control.
The code sample uses the one CheckedListBox control named CheckedListBox1 and one Listbox control named Listbox1. On the button click event all checked items in the CheckedListBox will bind in the listbox control.

Get checked items in checkedlistbox
Get checked items in checkedlistbox

Bind the items in CheckedListBox

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BindCheckedList()
    End Sub
 
    Private Sub BindCheckedList()
        CheckedListBox1.Items.Add("Author")
        CheckedListBox1.Items.Add("John")
        CheckedListBox1.Items.Add("Mohan")
        CheckedListBox1.Items.Add("James")
        CheckedListBox1.Items.Add("Ankur")
        CheckedListBox1.Items.Add("Robert")
    End Sub

Get selected items of CheckedListBox1 and bind into ListBox1.

    Private Sub Button1_Click(ByVal sender As System.Object,
                          ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Clear()
        If CheckedListBox1.CheckedItems.Count > 0 Then
            For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
                ListBox1.Items.Add(CheckedListBox1.CheckedItems(i))
            Next
        End If
    End Sub

2 thoughts on “Get selected items in a Checkbox List in vb.net”

  1. hello im pulling my hair because this problem, can you help my how to insert list item into database, get the value item and display it into checkbox not as lable or text

  2. Why is the article about getting the *SELECTED* items… really only getting the *CHECKED* items instead???

Comments are closed.