Copy selected CheckedItems to another CheckedListBox : CheckedListBox « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » CheckedListBox 
23.28.5.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(1313);
        this.checkedListBoxPossibleValue.Name = "checkedListBoxPossibleValue";
        this.checkedListBoxPossibleValue.Size = new System.Drawing.Size(187242);

        this.buttonMove.Location = new System.Drawing.Point(207129);
        this.buttonMove.Text = "Move";
        this.buttonMove.Click += new System.EventHandler(this.buttonMove_Click);

        this.listBoxSelected.FormattingEnabled = true;
        this.listBoxSelected.Location = new System.Drawing.Point(28813);
        this.listBoxSelected.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
        this.listBoxSelected.Size = new System.Drawing.Size(187238);

        this.AutoScaleBaseSize = new System.Drawing.Size(513);
        this.ClientSize = new System.Drawing.Size(492273);
        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());
    }
}
23.28.CheckedListBox
23.28.1.CheckedListBox: get selection stateCheckedListBox: get selection state
23.28.2.CheckedListBox: set item selectedCheckedListBox: set item selected
23.28.3.CheckedListBox: checked and selected item countCheckedListBox: checked and selected item count
23.28.4.CheckedListBox: selected change eventCheckedListBox: selected change event
23.28.5.Copy selected CheckedItems to another CheckedListBox
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.