C#開発日記(.NET FrameWork)|初心者から上級者まで|C#プログラミングでわからない事を解決する方法>チェックリストボックスでチェックされたものを調べる方法

checkedListBoxでチェックされたものを調べる方法


using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;


namespace ui057

{

   /// <summary>

   /// Form1 の概要の説明です。

   /// </summary>

   public class Form1 : System.Windows.Forms.Form

{

           private System.Windows.Forms.Button button1;

           private System.Windows.Forms.CheckedListBox checkedListBox1;

   /// <summary>

   /// 必要なデザイナ変数です。

   /// </summary>

   private System.ComponentModel.Container components = null;


   public Form1()

{

           //

   // Windows フォーム デザイナ サポートに必要です。

   //

   InitializeComponent();

                   //

   // TODO: InitializeComponent 呼び出しの後に、

                   //コンストラクタ コードを追加してください。

   //

}


/// <summary>

/// 使用されているリソースに後処理を実行します。

/// </summary>

protected override void Dispose( bool disposing )

  {

     if( disposing )

      {

      if (components != null)

         {

 components.Dispose();

 }

      }

base.Dispose( disposing );

           }


///#region Windows フォーム デザイナで生成されたコード

/// <summary>

/// デザイナ サポートに必要なメソッドです。このメソッドの内容を

/// コード エディタで変更しないでください。

/// </summary>

private void InitializeComponent()

{

                this.button1 = new System.Windows.Forms.Button();

                this.checkedListBox1

                      = new System.Windows.Forms.CheckedListBox();

                this.SuspendLayout();

                //

                // button1

                //

                this.button1.Location = new System.Drawing.Point(167, 83);

                this.button1.Name = "button1";

                this.button1.Size = new System.Drawing.Size(75, 24);

                this.button1.TabIndex = 3;

                this.button1.Text = "確認";

                this.button1.Click += new System.EventHandler

                                                     (this.button1_Click);

                //

                // checkedListBox1

                //

                this.checkedListBox1.Items.AddRange(new object[] {

                                                            "あらいぐま",

                                                            "パンダ",

                                                            "シマリス",

                                                            "キリン",

                                                            "アフリカゾウ",

                                                            "チンパンジー",

                                                            "シマウマ"});

          this.checkedListBox1.Location = new System.Drawing.Point(15, 19);

          this.checkedListBox1.Name = "checkedListBox1";

          this.checkedListBox1.Size = new System.Drawing.Size(136, 88);

          this.checkedListBox1.TabIndex = 2;

          //

          // Form1

          //

          this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);

          this.ClientSize = new System.Drawing.Size(256, 126);

          this.Controls.Add(this.button1);

          this.Controls.Add(this.checkedListBox1);

          this.Name = "Form1";

          this.Text = "Form1";

          this.ResumeLayout(false);


        }

#endregion


/// <summary>

/// アプリケーションのメイン エントリ ポイントです。

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}


        private void button1_Click(object sender, System.EventArgs e)

        {

            string SelectString = "★選択した項目\n\r";


            // 選択されている項目を取得する

            if(checkedListBox1.SelectedItem != null)

                SelectString += " " + checkedListBox1

                    .SelectedItem.ToString();


            // チェックされている項目を取得する

            SelectString += "\n\r\n\r★チェックした項目";

            foreach(Object CheckItem in checkedListBox1.CheckedItems)

                SelectString += "\n\r " + CheckItem.ToString();

            MessageBox.Show(SelectString, "確認");

        }

    }

 }

C#開発日記(.NET FrameWork)|初心者から上級者まで|C#プログラミングでわからない事を解決する方法

トップページ
特殊文字とは
起動時のパラメータ取得方法
C#プログラミング文字列を連結する方法
C#でのファイルの書き込み
文字列の分割の方法
C#のファイルパス名文字列から、ファイル名や拡張子を抜きだす方法
C#文字列扱いの方法etc
ダイアログで複数ファイル名を読む方法
動的配列の取り方
チェックリストボックスでチェックされたものを調べる方法
C#ファイルからの入力
文字列の検索方法
四捨五入する方法
小数点操作のいろいろ
型変換による精度保持の方法
内部変換誤差のお話
C#で数値を文字列に変換する方法
算術演算 (関数) の記述
C#ファイルの移動
C#フォームをアクティブにする方法
Formを必ず最前面に移動しその Form にフォーカスを移動する
C#で時間差表示する方法
Form の多重起動を防ぐ
Form を最前面に\配置
Formを自動で閉じる
VisualStudioでセットアップモジュールを作る方法
*
*
*
(以下は用語説明文)
.NET Framework

その他

リンク集







inserted by FC2 system