Click here to Skip to main content
15,117,794 members
Articles / Programming Languages / C#
Tip/Trick
Posted 14 May 2011

Tagged as

Stats

35.2K views
888 downloads
6 bookmarked

CheckList Box and List Box

Rate me:
Please Sign up or sign in to vote.
3.71/5 (6 votes)
14 May 2011CPOL
How to show the checked items of the check list box in listbox?

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:

C#
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#.

Image 1

1. Form is loaded with items in both checkbox list.

Image 2

2. Checked items are shown in the list box form the checkbox list.

Image 3

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Santoshshrest
Software Developer
Nepal Nepal
No Biography provided

Comments and Discussions

 
GeneralMy vote of 1 Pin
Warrick Procter16-May-11 10:03
MemberWarrick Procter16-May-11 10:03 
I do not think this is an article. There needs to be much more meat for it to be useful even for a beginner.

If I remove all the headings and captions I am left with six lines of text:

This post is about how to work with checklist box and list box.
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.
The basic code is given below:
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."


I will come back and revise this score if/when the article is more substantial.

Good luck, Warrick

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.