Skip to main content

RepositoryItemCheckedComboBoxEdit.EditValueType Property

Gets or sets whether the editor’s EditValue property returns a List<T> object that contains the selected item values or a String object that contains the string representations of these values, separated by a comma (or a custom character) and a space character.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DefaultValue(EditValueTypeCollection.CSV)]
[DXCategory("Data")]
public EditValueTypeCollection EditValueType { get; set; }

Property Value

Type Default Description
EditValueTypeCollection CSV

An EditValueTypeCollection enumeration value that specifies the type of the EditValue property value.

Available values:

Name Description
CSV

A String object that contains the string representations of the selected item values, separated by a comma (or a custom character) and a space character.

List

A List<T> object that contains the selected item values.

Remarks

The EditValueType property specifies the type of the object that the EditValue property returns:

  • List — a List<T> object that contains the selected item values. To specify an item’s value, use the Value property.
  • CSV — a String object that contains the string representations of these values, separated by a comma (or a custom character) and a space character. To specify a custom separator, use the SeparatorChar property.

If the editor displays a set of flags (see SetFlags(Type)), the EditValue returns a bitwise combination of the selected flags.

The ForceUpdateEditValue property specifies how the EditValue property is synchronized with the selection in the drop-down list. In bound mode, the edit value is synchronized with the selection in the drop-down list.

In unbound mode, the edit value is not synchronized with the selection in the drop-down list. In this mode, do not set the EditValue directly, use the SetEditValue(Object) method instead. Depending on the EditValueType property value, pass an Object that specifies a value (or its string representation), a List<T> of values, or a bitwise combination of flags as a parameter.

checkedComboBoxEdit1.Properties.Items.Add(true, "Yes");
checkedComboBoxEdit1.Properties.Items.Add(false, "No");

//The edit value is a string.
checkedComboBoxEdit1.Properties.EditValueType = EditValueTypeCollection.CSV;
checkedComboBoxEdit1.SetEditValue(true);
//You can also pass the value's string representation.
checkedComboBoxEdit1.SetEditValue("True");

//The edit value is a list.
checkedComboBoxEdit1.Properties.EditValueType = EditValueTypeCollection.List;
checkedComboBoxEdit1.SetEditValue(new List<bool>() { true });

//The editor displays a set of flags.
checkedComboBoxEdit2.Properties.SetFlags(typeof(MultiHue));
checkedComboBoxEdit2.SetEditValue(MultiHue.Red | MultiHue.Green);

Note

You cannot assign a CheckedComboBoxEdit that contains a BindingList<T> to a GridColumn since the GridControl creates detail views for data fields that contain collections. Use this edit value type for standalone editors only.

Examples

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;

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 snippet (auto-collected from DevExpress Examples) contains a reference to the EditValueType 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