articles

home / developersection / articles / checkedlistbox control in vb.net

CheckedListBox Control in VB.Net

Pushpendra Singh 13.91 K 11-Dec-2010

CheckedListBox is a combination of a ListBox and a CheckBox. CheckedListBox can have items added using the String Collection Editor or their items can add dynamically from a collection at run time, using the Items property.

Drag and drop a CheckedListBox from toolbox on the window form

CheckOnClick property should be true in CheckedListBox so that when you click on the Text then references checkbox is checked.

Code:

Public Class mindstick
 
    Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged
 
        Label2.Text = "You selected  " + CheckedListBox1.SelectedItem.ToString()
    End Sub
    Private Sub mindstick_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Here items is added in the CheckedListBox1
        CheckedListBox1.Items.Add("C#")
        CheckedListBox1.Items.Add("J#")
        CheckedListBox1.Items.Add("VB")
    End Sub
End Class

In above code Item is added dynamically so all Item in CheckedListBox1  will show at run time.

Run the project

When you select the given option then SelectedIndexChanged event will fire and selected value will show in the Label.

Change CheckedListBox Appearance

Set the forecolor of checkedListBox on FormLoad event as

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CheckedListBox1.ForeColor = Color.Green
End Sub

ForeColor of CheckedListBox will be changed at run time.

Output:


Updated 07-Sep-2019

Leave Comment

Comments

Liked By