CheckedListBox.CheckOnClick プロパティ

定義

項目が選択されたときに、チェック ボックスを切り替えるかどうかを示す値を取得または設定します。Gets or sets a value indicating whether the check box should be toggled when an item is selected.

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

プロパティ値

Boolean

すぐにチェック マークが適用される場合は true。それ以外の場合は falsetrue if the check mark is applied immediately; otherwise, false. 既定値は、false です。The default is false.

次のコード例では CheckedListBox 、、、およびの各プロパティを設定して、コントロールを初期化する方法を示し CheckOnClick SelectionMode ThreeDCheckBoxes ます。The following code example demonstrates initializing a CheckedListBox control by setting the CheckOnClick, SelectionMode, and ThreeDCheckBoxes properties. この例では、を CheckedListBox コントロールに設定し、を DisplayMember Control.Name コントロールのプロパティに設定します。The example populates the CheckedListBox with controls and sets the DisplayMember to the Control.Name property of the control.

この例を実行するには、という名前のを含むフォームに次のコードを貼り付け、 CheckedListBox CheckedListBox1 InitializeCheckListBox フォームのコンストラクターまたは Load メソッドからメソッドを呼び出します。To run the example, paste the following code in a form containing a CheckedListBox named CheckedListBox1 and call the InitializeCheckListBox method from the form's constructor or Load method.

   // 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 項目が選択されるたびに、チェックボックスを切り替えるかどうかを示します。CheckOnClick indicates whether the check box should be toggled whenever an item is selected. 既定の動作では、最初のクリック時に選択範囲を変更し、ユーザーがもう一度クリックしてチェックマークを適用します。The default behavior is to change the selection on the first click, and then have the user click again to apply the check mark. ただし、場合によっては、クリックされるとすぐに項目をチェックすることもできます。In some instances, however, you might prefer have the item checked as soon as it is clicked.

適用対象