spspli
spspli

Reputation: 3338

Can I set the datasource for a column in grid, only for one specific row?

Hi I have the following requirement: A grid control in devexpress for winform. Column 1 for this grid is a repositoryItemCheckedComboBoxEdit, how could I get the current row and then reset the datasource for the repositoryItemCheckedComboBoxEdit just for this row?

Upvotes: 0

Views: 3630

Answers (2)

DevExpress Team
DevExpress Team

Reputation: 11376

Such tasks are usually implemented using the GridView's ShownEditor event. You should determine the currently focused column and its FieldName (GridView.FocusedColumn.FieldName) and then change the editor's DataSource property based on the value saved in another cell of this record. I.e.

private void gridView1_ShownEditor(object sender, EventArgs e) {
            GridView gridView = sender as GridView;
            if(gridView.FocusedColumn.FieldName == "YourField") {
                CheckedComboBoxEdit edit = gridView.ActiveEditor as CheckedComboBoxEdit;
                object value = gridView.GetRowCellValue(gridView.FocusedRowHandle, "AnotherColumn");
                // filter the datasource and set the editor's DataSource:
                edit.Properties.DataSource = FilteredDataSource;// your value
            }
        }

Also, please take a look at the How to filter a second LookUp column based on a first LookUp column's value article where a similar task is resolved.

Upvotes: 2

SLaks
SLaks

Reputation: 888047

You can handle the FocusedRowChanged event, then set the DataSource based on the view's GetFocusedRow().

You may need to have a separate editor with a complete datasource to show values in non-focused columns, and handle CustomRowCellEditForEditing to use the subset in edit mode.

Upvotes: 0

Related Questions