Filter GridView combobox cell differently for each row

1 Answer 29 Views
Top achievements
Rank 1
Richard asked on 23 Aug 2022, 07:11 PM

I have an application I'm upgrading from an old control set where this worked before.

The requirement that I have is that for each row, when a value is entered in the first column, I need to filter down the available items in a second combobox column on that row.  This changes row per row depending on what was entered in the first column.  

eg: If I enter "colour" in the first column, I need to see colours in the combobox. If I enter "shape" in the first column, I need to see shapes, in the combobox.

It's functionally working right now by just setting the datasource for the combobox to be a DataTables DefaultView that I'm just adjusting the row filter for.

//Set datasource
combo.DataSource = dt.DefaultView;

//Later on update filter to change values
dt.DefaultView.RowFilter = "some_id_column = " + id_to_filter_by;

But, every time I select a different row that doesn't match the filter pattern, the second column looks blank as the RowFilter changes.  The value is retained as part of the backing grid datasource, but it clumsy as the display text can look blank on any unselected rows.

Is there any way around this by changing the filter or data source directly on the cells instead of the column?  That way I could adjust it for each row without it effecting all rows?

1 Answer, 1 is accepted

Sort by
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Aug 2022, 04:36 AM

Hi, Richard,

The described functionality you are looking for is the commonly known cascading comboboxes scenario. I would highly encourage you to have a look at the following KB article which is quite useful on this topic: 

Note that the main idea is to set the DataSource property of the GridViewComboBoxColumn to the full list of all available options in the column. Then, when the editor for this column is initialized, a subset collection can be applied to the editor. Thus, the already stored values within the cells will not disappear.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Dess | Tech Support Engineer, Principal
Progress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.

Top achievements
Rank 1
commented on 24 Aug 2022, 03:54 PM | edited

This totally solved my issue.  I'd read the article but for some reason kept thinking it was parent/child across grids.

One thing I did have to omit from my side was on step #4, I had to remove the following code. 

editorElement.SelectedValue = null;
editorElement.SelectedValue = this.radGridView1.CurrentCell.Value;

This would constantly set the selected value to null for some reason for me.  Removing it had everything work as expected.

Here's what I ended up with.

RadDropDownListEditor editor;
RadDropDownListEditorElement editorElement;


if (e.Column.FieldName == "field_being_edited") {

var cell = radGrid.CurrentRow.Cells["parent_field"]; if (cell.Value == DBNull.Value || cell.Value == null) { return; } editor = radGrid.ActiveEditor as RadDropDownListEditor; editorElement = editor.EditorElement as RadDropDownListEditorElement; var dt = dataProvider.GetChildForParent(Convert.ToInt32(cell.Value)); editorElement.DataSource = dt; }

Asked by
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question