Introduction
This post is about how to work with checklist box and list box.
Background
The earlier post showed how to load the form with checked items is the checklist box.
This one is to show which items are checked in the check list box in list box.
Using the Code
The basic code is given below:
public Form1()
{
InitializeComponent();
checkedListBox1.Items.Add("PHP");
checkedListBox1.Items.Add("Flash");
checkedListBox1.Items.Add("C/C++");
checkedListBox1.Items.Add("MCTS");
checkedListBox1.Items.Add("MCSE");
checkedListBox1.Items.Add("Red Hat");
checkedListBox2.Items.Add("RHCE 125");
checkedListBox2.Items.Add("RHCE 255");
checkedListBox2.Items.Add("Let Us C");
checkedListBox2.Items.Add("Black Book Of MCTS");
}
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (e.NewValue == CheckState.Checked)
{
listBox1.Items.Add(checkedListBox1.Text);
}
else if (e.NewValue == CheckState.Unchecked)
{
listBox1.Items.Remove(checkedListBox1.Text);
}
}
private void checkedListBox2_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (e.NewValue == CheckState.Checked)
{
listBox2.Items.Add(checkedListBox2.Text);
}
else if (e.NewValue == CheckState.Unchecked)
{
listBox2.Items.Remove(checkedListBox2.Text);
}
}
}
The above is written in Visual C#.
1. Form is loaded with items in both checkbox list.
2. Checked items are shown in the list box form the checkbox list.
3. Checked items are removed form the listbox.
History
In the previous CheckListBox
, we learned about the checked items.
In this, the base is the same but the difference is showing the checked list items in list box.
Thank you.
Santosh Shrestha.