Fils
Fils

Reputation: 47

How to make a column of CheckedComboBoxEdit in GridControl with different sourcedata for each row?

I have problem with DevExpress XtraGrid. I wont to make a column of CheckedComboBoxEdit's, but i dont know how to make them work separately. For example, in first row my CheckedComboBoxEdit will contain "a" and "b", and in second "b", "c", "d".

I thought i can use sth like this:

    List<CheckedListBoxItem> listOfCheckedItems = new List<CheckedListBoxItem>();
    listOfCheckedItems.Add( new CheckedListBoxItem( "test" ) );
    CheckedComboBoxEdit checkedCombo = new CheckedComboBoxEdit();
    gridView1.AddNewRow();
    gridView1.SetRowCellValue( gridView1.RowCount - 1, gridView1.Columns[ 1 ], checkedCombo );

Where: gridView1 is MainView of my gridControl.

Upvotes: 0

Views: 1460

Answers (1)

nempoBu4
nempoBu4

Reputation: 6621

You can use ColumnView.ShownEditor event and ColumnView.FocusedRowHandle and ColumnView.FocusedColumn and ColumnView.ActiveEditor properties.
Here is example:

private void gridView1_ShownEditor(object sender, EventArgs e)
{
    if (gridView1.FocusedColumn.FieldName != "YourCheckedComboBoxColumn")
        return;

    var editor = (CheckedComboBoxEdit)gridView1.ActiveEditor;
    editor.Properties.Items.Clear();

    var value = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "YourEyeColumn").ToString();

    if (value == "Eye Color")
        editor.Properties.Items.AddRange(new CheckedListBoxItem[] { new CheckedListBoxItem("Green"), new CheckedListBoxItem("Blue"), new CheckedListBoxItem("Grey") });
    else if (value == "Eye Size")
        editor.Properties.Items.AddRange(new CheckedListBoxItem[] { new CheckedListBoxItem("Big"), new CheckedListBoxItem("Medium"), new CheckedListBoxItem("Small") });
}

Upvotes: 1

Related Questions