CheckedListBox.CheckOnClick プロパティ

定義

項目が選択されたときに、チェック ボックスを切り替えるかどうかを示す値を取得または設定します。

public:
 property bool CheckOnClick { bool get(); void set(bool value); };
public bool CheckOnClick { get; set; }
member this.CheckOnClick : bool with get, set
Public Property CheckOnClick As Boolean

プロパティ値

すぐにチェック マークが適用される場合は true。それ以外の場合は false。 既定値は、false です。

次のコード例では、および ThreeDCheckBoxes プロパティをCheckedListBox設定してコントロールを初期化する方法をCheckOnClickSelectionMode示します。 この例では、 に CheckedListBox コントロールを設定し、 を DisplayMember コントロールの プロパティに Control.Name 設定します。

この例を実行するには、 という名前CheckedListBox1の を含むフォームに次のコードをCheckedListBox貼り付け、フォームのコンストラクターまたは Load メソッドから メソッドを呼び出InitializeCheckListBoxします。

   // This method initializes CheckedListBox1 with a list of all 
   // the controls on the form. It sets the selection mode
   // to single selection and allows selection with a single click.
   // It adds itself to the list before adding itself to the form.
internal:
   System::Windows::Forms::CheckedListBox^ CheckedListBox1;

private:
   void InitializeCheckedListBox()
   {
      this->CheckedListBox1 = gcnew CheckedListBox;
      this->CheckedListBox1->Location = System::Drawing::Point( 40, 90 );
      this->CheckedListBox1->CheckOnClick = true;
      this->CheckedListBox1->Name = "CheckedListBox1";
      this->CheckedListBox1->Size = System::Drawing::Size( 120, 94 );
      this->CheckedListBox1->TabIndex = 1;
      this->CheckedListBox1->SelectionMode = SelectionMode::One;
      this->CheckedListBox1->ThreeDCheckBoxes = true;
      System::Collections::IEnumerator^ myEnum = this->Controls->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Control^ aControl = safe_cast<Control^>(myEnum->Current);
         this->CheckedListBox1->Items->Add( aControl, false );
      }

      this->CheckedListBox1->DisplayMember = "Name";
      this->CheckedListBox1->Items->Add( CheckedListBox1 );
      this->Controls->Add( this->CheckedListBox1 );
   }
// This method initializes CheckedListBox1 with a list of all 
// the controls on the form. It sets the selection mode
// to single selection and allows selection with a single click.
// It adds itself to the list before adding itself to the form.

internal System.Windows.Forms.CheckedListBox CheckedListBox1;

private void InitializeCheckedListBox()
{
    this.CheckedListBox1 = new CheckedListBox();
    this.CheckedListBox1.Location = new System.Drawing.Point(40, 90);
    this.CheckedListBox1.CheckOnClick = true;
    this.CheckedListBox1.Name = "CheckedListBox1";
    this.CheckedListBox1.Size = new System.Drawing.Size(120, 94);
    this.CheckedListBox1.TabIndex = 1;
    this.CheckedListBox1.SelectionMode = SelectionMode.One;
    this.CheckedListBox1.ThreeDCheckBoxes = true;

    foreach ( Control aControl in this.Controls )
    {
        this.CheckedListBox1.Items.Add(aControl, false);
    }

    this.CheckedListBox1.DisplayMember = "Name";
    this.CheckedListBox1.Items.Add(CheckedListBox1);
    this.Controls.Add(this.CheckedListBox1);
}
' This method initializes CheckedListBox1 with a list of all the controls
' on the form. It sets the selection mode to single selection and
' allows selection with a single click. It adds itself to the list before 
' adding itself to the form.
Friend WithEvents CheckedListBox1 As System.Windows.Forms.CheckedListBox

Private Sub InitializeCheckedListBox()
    Me.CheckedListBox1 = New CheckedListBox
    Me.CheckedListBox1.Location = New System.Drawing.Point(40, 90)
    Me.CheckedListBox1.CheckOnClick = True
    Me.CheckedListBox1.Name = "CheckedListBox1"
    Me.CheckedListBox1.Size = New System.Drawing.Size(120, 94)
    Me.CheckedListBox1.TabIndex = 1
    Me.CheckedListBox1.SelectionMode = SelectionMode.One
    Me.CheckedListBox1.ThreeDCheckBoxes = True

    Dim aControl As Control
    For Each aControl In Me.Controls
        Me.CheckedListBox1.Items.Add(aControl, False)
    Next

    Me.CheckedListBox1.DisplayMember = "Name"
    Me.CheckedListBox1.Items.Add(CheckedListBox1)
    Me.Controls.Add(Me.CheckedListBox1)
End Sub

注釈

CheckOnClick は、項目が選択されるたびにチェック ボックスを切り替える必要があるかどうかを示します。 既定の動作では、最初のクリックで選択内容を変更してから、ユーザーがもう一度クリックしてチェック マークを適用します。 ただし、一部の場合は、クリックされた直後に項目をオンにすることをお勧めします。

適用対象