articles

Home / DeveloperSection / Articles / CheckedListBox Control in C#.net

CheckedListBox Control in C#.net

CheckedListBox Control in C#.net

Pushpendra Singh 26792 24-Jan-2011

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.

How to use CheckedListBox Control

Drag and drop a CheckedListBox from toolbox on the windowForm.

CheckedListBox Control in C#.net

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

Code:

 

using System;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }
        private void Form5_Load(object sender, EventArgs e)
        {
            // add item in checkedListBox
            checkedListBox1.Items.Add("C#");
            checkedListBox1.Items.Add("VB");
            checkedListBox1.Items.Add("Java");
        }
        private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Show selected Item in Label
            label1.Text = "Selected Language is  " + checkedListBox1.SelectedItem.ToString();
        }
    }
}

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

Run the application

CheckedListBox Control in C#.net

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

CheckedListBox Control in C#.net

CheckedListBox Properties

CheckOnClick:   Indicates whether the check box should be toggled when an item is selected.

Multicolumn :  Indicates whether the CheckedListBox supports multiple columns.

BackColor:   BackColor of CheckedListBox can be changed through BackColor property.

Example:

private void Form5_Load(object sender, EventArgs e)
{
       // change BackColor of checkedListBox
       checkedListBox1.BackColor = Color.CadetBlue;
}


CheckedListBox Control in C#.net

   SelectedItem  : Gets or sets the currently selected item in the CheckedListBox. 


You must be read this Article :- Print and Print Preview separately using HTML, CSS and JavaScript


Updated 04-Mar-2020

Leave Comment

Comments

Liked By