Search code examples
c#winformsdevexpressxtragridxtraeditors

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?


Solution

  • 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.