CheckedListBox.CheckOnClick Property

Gets or sets a value indicating whether the check box should be toggled when an item is selected.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public bool CheckOnClick { get; set; }

Property Value

Type: System.Boolean
true if the check mark is applied immediately; otherwise, false. The default is false.

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.

The following code example demonstrates initializing a CheckedListBox control by setting the CheckOnClick, SelectionMode, and ThreeDCheckBoxes properties. The example populates the CheckedListBox with controls and sets the DisplayMember to the Control.Name property of the control.

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 = 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);
	}
The following code example demonstrates initializing a CheckedListBox control by setting the CheckedListBox.CheckOnClick, CheckedListBox.SelectionMode, and CheckedListBox.3DCheckBoxes properties. The example populates the 
CheckedListBox with controls and sets the CheckedListBox.Display member to the name property of the control.

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.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft