In this C# example, I’ll show you How to move data from one CheckedListBox to another CheckedListBox .
In our first approach, we are going to create CheckedListBox and Button Controls at design-time using the Forms designer.
Form_Load Code
1 2 3 4 5 6 7 8 9 10 11 | private void Form1_Load(object sender, EventArgs e) { checkedListBox1.Items.Add("C#"); checkedListBox1.Items.Add("C++"); checkedListBox1.Items.Add("Python"); checkedListBox1.Items.Add("Java"); checkedListBox1.Items.Add("PHP"); checkedListBox1.Items.Add("ASP.NET"); } |
Button1_Click Code: (CheckedListBox1 >> CheckedListBox2)
1 2 3 4 5 6 7 8 9 10 | private void button1_Click(object sender, EventArgs e) { foreach (string item in checkedListBox1.CheckedItems.OfType<string>().ToList()) { checkedListBox2.Items.Add(item); checkedListBox1.Items.Remove(item); } } |
Button2_Click Code: (CheckedListBox2 >> CheckedListBox1)
1 2 3 4 5 6 7 8 9 10 | private void button2_Click(object sender, EventArgs e) { foreach (string item in checkedListBox2.CheckedItems.OfType<string>().ToList()) { checkedListBox1.Items.Add(item); checkedListBox2.Items.Remove(item); } } |