Skip to main content
A newer version of this page is available. .

CheckEdit Class

Allows an end-user to select between two (checked and unchecked) or three (checked, unchecked and indeterminate) states. Multiple CheckEdit controls can be combined into a logical radio-group.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v17.2.dll

Declaration

[ToolboxBitmap(typeof(ToolboxIconsRootNS), "CheckEdit")]
[ToolboxTabName("DX.17.2: Common Controls")]
[DefaultBindingPropertyEx("CheckState")]
public class CheckEdit :
    BaseCheckEdit

Remarks

A CheckEdit control displays a check box and a caption.

CheckEdit_Class.gif

According to the RepositoryItemCheckEdit.AllowGrayed setting, the CheckEdit control supports two (checked and unchecked) or three (checked, unchecked and indeterminate) check states.

Multiple check box styles are available (see RepositoryItemCheckEdit.CheckStyle). Additionally, you can assign your own images to be displayed as a check box glyph using the RepositoryItemCheckEdit.PictureChecked, RepositoryItemCheckEdit.PictureUnchecked and RepositoryItemCheckEdit.PictureGrayed properties. Check box alignment within a check editor is specified by the BaseRepositoryItemCheckEdit.GlyphAlignment property.

The control’s caption can be set with the BaseCheckEdit.Text or the BaseRepositoryItemCheckEdit.Caption property. To hide the caption, you can clear these properties, or set the BaseRepositoryItemCheckEdit.GlyphAlignment option to Center.

A user can toggle check states by clicking the editor with the mouse or by pressing the SPACE key. To set the state programmatically, use either the CheckEdit.Checked or CheckEdit.CheckState property. CheckEdit.Checked is Boolean and can identify only checked and unchecked states.

If the check editor supports three states (see RepositoryItemCheckEdit.AllowGrayed), use the CheckEdit.CheckState property. In the indeterminate state, the check box is displayed with a dimmed appearance, based on the RepositoryItemCheckEdit.NullStyle property.

It is possible to associate any values (not only Boolean values) with the checked, unchecked and grayed states. To accomplish this, use the RepositoryItemCheckEdit.ValueChecked, RepositoryItemCheckEdit.ValueUnchecked and RepositoryItemCheckEdit.ValueGrayed properties. When an editor’s state is modified (e.g., when an end-user toggles the check box), a corresponding value (ValueChecked, ValueUnchecked or ValueGrayed) is assigned to the CheckEdit.EditValue property. Conversely, when the CheckEdit.EditValue property is set to either ValueChecked, ValueUnchecked or ValueGrayed in code, the check box is set to the corresponding check state and the CheckEdit.Checked and CheckEdit.CheckState properties are set accordingly.

If the editor is bound to a data source field, ensure that the types of the ValueChecked, ValueUnchecked or ValueGrayed values match the bound field’s type.

The example below shows how to set the ValueChecked, ValueUnchecked and ValueGrayed properties to Byte values:


checkEdit1.Properties.ValueChecked = (byte)2;
checkEdit1.Properties.ValueGrayed = (byte)1;
checkEdit1.Properties.ValueUnchecked = (byte)0;

Multiple CheckEdit controls can be combined into a logical group of mutually exclusive options (as in a radio-group). Use the RepositoryItemCheckEdit.RadioGroupIndex property to do this. Alternatively, you can use the RadioGroup control to implement a logical group of options.

When creating multiple CheckEdit controls, you can also use the CheckedListBoxControl control. This control is easier to use for creating a set of check boxes using data binding, while separate CheckEdit editors give you greater control over the layout.

Example

This example demonstrates how to programmatically create two check editors, initialize their properties and assign the same handler for their CheckEdit.CheckedChanged events. The created check editors will be used to control the visibility and availability of a standard button control. The example implies that the button is already placed onto a form.

Changing the check state of the first check editor affects both the button’s visibility and the second check editor’s availability. The second check editor specifies the availability of the button for end-users.

The image below displays the example application.

CheckEdit_CheckedChanged_Example.gif

using DevExpress.XtraEditors;
using DevExpress.Utils;

private void CreateCheckEditors() {
    // creating and initializing the first check editor
    CheckEdit chEdit1 = new CheckEdit();
    chEdit1.Properties.Caption = "Hide Button";
    chEdit1.Name = "chEdit1";
    chEdit1.Location = new System.Drawing.Point(6, 35);
    chEdit1.Width = 100;
    // setting the editor's check state depending upon the button's visibility
    if (!(button1.Visible)) chEdit1.Checked = true;
    // assigning a handler for the CheckChanged event of the first check editor
    chEdit1.CheckedChanged += new EventHandler(CheckedChanged);
    this.Controls.Add((Control)chEdit1);

    // creating and initializing the second check editor
    CheckEdit chEdit2 = new CheckEdit();
    chEdit2.Properties.Caption = "Disable Button";
    chEdit2.Name = "chEdit2";
    chEdit2.Location = new System.Drawing.Point(6, 55);
    chEdit2.Width = 100;
    // setting the editor's check state depending upon the button's availability
    if (!(button1.Enabled)) chEdit2.Checked = true;
    if (!(button1.Visible)) chEdit2.Enabled = false;
    // assigning a handler for the CheckChanged event of the second check editor
    chEdit2.CheckedChanged += new EventHandler(CheckedChanged);
    this.Controls.Add((Control)chEdit2);
}

private void CheckedChanged(object sender, System.EventArgs e) {
    CheckEdit edit = sender as CheckEdit;
    switch (edit.Checked) {
        case true:
            if (edit == GetCheckEdit("chEdit1")){
                // hiding the button
                button1.Visible = false;
                // disabling the second check editor
                GetCheckEdit("chEdit2").Enabled = false;
            }
            else if (edit == GetCheckEdit("chEdit2")){
                // enabling the button
                button1.Enabled = false;
            }
            break;
        case false:
            if (edit == GetCheckEdit("chEdit1")){
                // showing the button
                button1.Visible = true;
                // enabling the second check editor
                GetCheckEdit("chEdit2").Enabled = true;
            }
            else if (edit == GetCheckEdit("chEdit2")){
                // disabling the button
                button1.Enabled = true;
            }
            break;
    }
}

private CheckEdit GetCheckEdit(string editName){
    foreach(Control control in this.Controls){
        if ((control is CheckEdit) && (control.Name == editName)) 
            return control as CheckEdit;
    }
    return null;
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the CheckEdit class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also