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

CheckedComboBoxEdit.EditValue Property

Gets or sets the editor’s edit value, which identifies checked items in the editor’s dropdown window.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v18.2.dll

Declaration

public override object EditValue { get; set; }

Property Value

Type Description
Object

An object that represents the editor’s edit value.

Remarks

If the editor is displaying bit fields, the edit value must be of the corresponding enumeration type, and must represent a set of flags to be checked in the dropdown.

If the editor is displaying Boolean options (not bit fields), the EditValue must specify a string or a List<object> instance (depending on the RepositoryItemCheckedComboBoxEdit.EditValueType property value).

To set an edit value in unbound mode, use the CheckedComboBoxEdit.SetEditValue method instead of direct assignment to the EditValue property.

In bound mode, the checked states of items in the dropdown are synchronized with the edit value, according to the RepositoryItemCheckedComboBoxEdit.ForceUpdateEditValue setting. See this link to learn more.

Example

The code below populates the RepositoryItemCheckedComboBoxEdit.Items collection with five items, each item stores a string value.

The CheckedComboBoxEdit.SetEditValue method is called to select “Circle” and “Ellipse” items. The “Circle” item is then disabled so that users cannot de-select it.

CheckedComboBoxEdit_ex

Note that the code modifies the RepositoryItemCheckedComboBoxEdit.SeparatorChar property to change the edit value separator char from the default comma (“,”) to a semicolon (“;”). The same separator char must be used in the SetEditValue method parameter.

// Add check items to the control's dropdown.
string[] itemValues = new string[] { 
    "Circle", "Rectangle", "Ellipse", 
    "Triangle", "Square" };
foreach (string value in itemValues)
    checkedComboBoxEdit1.Properties.Items.Add(value, CheckState.Unchecked, true);
// Specify the separator character.
checkedComboBoxEdit1.Properties.SeparatorChar = ';';
// Set the edit value.
checkedComboBoxEdit1.SetEditValue("Circle; Ellipse");
// Disable the Circle item.
checkedComboBoxEdit1.Properties.Items["Circle"].Enabled = false;

Example

The following example shows how to edit bit fields (a set of flags) in a CheckedComboBoxEdit control.

The control displays values of a custom MyColors enum, which has five simple flags (None through Yellow) and one combined flag (Green). Combined flags are not supported by the CheckedComboBoxEdit control. Items that correspond to these flags must be manually removed from the RepositoryItemCheckedComboBoxEdit.Items collection (see the removeCombinedFlags method which performs this operation).

The RepositoryItemCheckedComboBoxEdit.SetFlags method populates the RepositoryItemCheckedComboBoxEdit.Items collection with items corresponding to all available flags (except for a flag with a zero value). Then, the removeCombinedFlags method is called to remove items corresponding to combined flags. Finally, the editor’s initial value is specified using the CheckedComboBoxEdit.SetEditValue method.

The following image shows the result:

CheckedComboBoxEdit_ex_Flags

Note that the Green flag is not present in the dropdown list, although you can set this flag to the control’s value.

using DevExpress.XtraEditors.Repository;

[Flags]
enum MyColors {
    None = 0x00,
    Black = 0x01,
    White = 0x02,
    Blue = 0x04,
    Yellow = 0x08,
    Green = Blue | Yellow
}

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();

        // Populate the Items collection with all available flags.
        checkedComboBoxEdit1.Properties.SetFlags(typeof(MyColors));
        // Remove items that correspond to compound flags.
        removeCombinedFlags(checkedComboBoxEdit1.Properties);
        // Set an initial value.
        checkedComboBoxEdit1.SetEditValue(MyColors.Black | MyColors.Green);
    }

    // Traverse through items and remove those that correspond to bitwise combinations of simple flags.
    private void removeCombinedFlags(RepositoryItemCheckedComboBoxEdit ri) {
        for (int i = ri.Items.Count - 1; i > 0; i--) {
            Enum val1 = ri.Items[i].Value as Enum;
            for (int j = i - 1; j >= 0; j--) {
                Enum val2 = ri.Items[j].Value as Enum;
                if (val1.HasFlag(val2)) {
                    ri.Items.RemoveAt(i);
                    break;
                }
            }
        }
    }
}

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

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