Click here to Skip to main content
15,942,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have got a checkedListBox where the items can be selected, I want the selected items to be shown in my listbox also...



private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (var item in this.checkedListBox1.CheckedItems)
{
listBox1.Show();
}
is it not working because the code should be written under the 'private void listBox1_SelectedIndexChanged(object sender, EventArgs e)' instead?


Also is it possible to ensure it is in the same order as the list in the checkedListBox?

What I have tried:

writing ' MessageBox.Show(item.ToString());' but this shows the selected items as a message instead of appearing in the listbox
Posted
Updated 6-Dec-17 16:38pm
v3

1 solution

try

private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
       {
           listBox1.Items.Clear();
           foreach (var item in this.checkedListBox1.CheckedItems)
           {
               listBox1.Items.Add(item);
           }
           listBox1.Show();
       }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900