Mega Code Archive

 
Categories / C# Tutorial / GUI Windows Forms
 

Copy selected CheckedItems to another CheckedListBox

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; class Form1 : Form {     public Form1() {         InitializeComponent();         this.checkedListBoxPossibleValue.Items.Add("Ten");     }     private void buttonMove_Click(object sender, EventArgs e) {         if (this.checkedListBoxPossibleValue.CheckedItems.Count > 0) {             this.listBoxSelected.Items.Clear();             foreach (string item in this.checkedListBoxPossibleValue.CheckedItems) {                 this.listBoxSelected.Items.Add(item.ToString());             }             for (int i = 0; i < this.checkedListBoxPossibleValue.Items.Count; i++)                 this.checkedListBoxPossibleValue.SetItemChecked(i, false);         }     }     private void InitializeComponent() {         this.checkedListBoxPossibleValue = new System.Windows.Forms.CheckedListBox();         this.buttonMove = new System.Windows.Forms.Button();         this.listBoxSelected = new System.Windows.Forms.ListBox();         this.SuspendLayout();         this.checkedListBoxPossibleValue.CheckOnClick = true;         this.checkedListBoxPossibleValue.FormattingEnabled = true;         this.checkedListBoxPossibleValue.Items.AddRange(new object[] {             "One",             "Two",             "Three",             "Four",             "Five",             "Six",             "Seven",             "Eight",             "Nine"});         this.checkedListBoxPossibleValue.Location = new System.Drawing.Point(13, 13);         this.checkedListBoxPossibleValue.Name = "checkedListBoxPossibleValue";         this.checkedListBoxPossibleValue.Size = new System.Drawing.Size(187, 242);         this.buttonMove.Location = new System.Drawing.Point(207, 129);         this.buttonMove.Text = "Move";         this.buttonMove.Click += new System.EventHandler(this.buttonMove_Click);         this.listBoxSelected.FormattingEnabled = true;         this.listBoxSelected.Location = new System.Drawing.Point(288, 13);         this.listBoxSelected.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;         this.listBoxSelected.Size = new System.Drawing.Size(187, 238);         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);         this.ClientSize = new System.Drawing.Size(492, 273);         this.Controls.Add(this.listBoxSelected);         this.Controls.Add(this.buttonMove);         this.Controls.Add(this.checkedListBoxPossibleValue);         this.Text = "List Boxes";         this.ResumeLayout(false);     }     private System.Windows.Forms.CheckedListBox checkedListBoxPossibleValue;     private System.Windows.Forms.Button buttonMove;     private System.Windows.Forms.ListBox listBoxSelected;     [STAThread]     static void Main() {         Application.EnableVisualStyles();         Application.Run(new Form1());     } }