如何在 CheckedComboBoxEdit 中允许多个选择?

How to allow more than one selection in a CheckedComboBoxEdit?

我正在我的应用程序中使用 DevExpress 控件。我正在使用 checkedComboBoxEdit 但是当我想要 select 两个选项时,我在控件中直接出现无效值错误。有人知道为什么以及我该如何解决它? 谢谢!美好的一天!

private void checkedComboBoxEdit1_EditValueChanged(object sender, EventArgs e)  
{ 
    foreach (int items in checkedComboBoxEdit1.Properties.Items.GetCheckedValues()) 
        Prueba(checkedComboBoxEdit1.Properties); 
} 

public void Prueba(RepositoryItemCheckedComboBoxEdit ri) 
{ 
    int cont = ri.Items.Count; 
    for (int i = 0; cont > i; i++) 
    {
        var valor = ri.Items[i].Value; 
    } 
}

请仔细阅读文档并考虑将此控件分配到字符串数据类型的列中,而不是某些数字列单元格中。 来自文档:CheckedComboBoxEdit Class

The editor's edit value (BaseEdit.EditValue) identifies all the selected options in the dropdown. With the RepositoryItemCheckedComboBoxEdit.EditValueType property, you can specify whether to form the edit value as a string or a list.

希望此信息能帮助您避免在网格控件中设置不正确的值,在进行选择后显示不正确值的验证消息。我通过指定数据源修改了 this DX 问题示例,并且在整数列中分配字符串后行为与预期相同。

RepositoryItemCheckedComboBoxEdit ccb = new RepositoryItemCheckedComboBoxEdit();
List<Student> data = new List<Student>();
for(int i = 0; i < 3; i++)
{
    data.Add(new Student() {Id=i, Name= $"Student {i}"});
}
ccb.EditValueType = EditValueTypeCollection.CSV; // It is default value
ccb.DataSource = new BindingSource(data, null);
ccb.ValueMember = "Id";
ccb.DisplayMember = "Name";
ccb.AllowMultiSelect = true;
ccb.EditValueChanged += Ccb_EditValueChanged;
//ccb.Buttons.Add(new DevExpress.XtraEditors.Controls.EditorButton());
//ccb.ButtonClick += Ccb_ButtonClick;
//ccb.Popup += Ccb_Popup;
gridView1.Columns["Name"].ColumnEdit = ccb;  // I have changed it from "ID" column to "Name" 

如果您将它分配给 ID 列,那么它将期望单元格中的整数值,因此会引发与您在编辑器中进行选择后遇到的错误相同的错误。