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.
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
When you select the given option then SelectedIndexChanged event will fire and selected value will show in the Label.
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;
}
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
Leave Comment