Update bound value on Selection Changed on a RadComboBox in a custom column

1 Answer 67 Views
ComboBox GridView
Ian
Top achievements
Rank 1
Ian asked on 23 Jun 2021, 10:26 AM

I've created a custom column for my RadGridView, where upon editing the cell, an appropriate control is shown - A RadComboBox for a boolean or an enumeration, a RadMaskedTextInput for text, and a RadMaskedNumericInput for numeric values.

This is working fine except for a slight issue with the custom column when it's using a RadComboBox. What I would like to happen is for the bound value of that cell to update as soon as the user selects a new value from the drop-down. However, the grid currently fires the CellEditEnded event only after the cell loses focus (or after the enter key is pressed), so the user has to select the item from the drop-down, and then click away from the cell for the change to take effect.

I was thinking that a solution for this would be to add an OnSelectionChanged handler to my dynamically-created RadComboBox, and then inside that handler, programmatically end/commit the edit, which would would cause the CellEditEnded event to be fired. However I can't seem to find a way to programmatically commit the edit from inside the custom column?

Alternatively, I was looking at whether the RadComboBox itself has a property that can force this required functionality, but I can't see that either. 

Thanks

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 25 Jun 2021, 10:53 AM

Hello Ian,

If I correctly understand your requirement, I believe the you can get ahold of the RadGridView control in your SelectionChanged event handler and call its CommitEdit method:

    public class CustomComboColumn : GridViewDataColumn
    {
        // ...

        private void Combo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.RemovedItems.Count > 0)
            {
                var combo = sender as RadComboBox;
                var grid = combo.ParentOfType<RadGridView>();
                grid.CommitEdit();
            }
        }
    }

You can also have a look at the following article which explains a similar solution.

Please let me know if this approach would work for you.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Ian
Top achievements
Rank 1
commented on 25 Jun 2021, 11:22 AM

Hi Dilyan. Yes, that's exactly what I needed! Thanks for the response.
Tags
ComboBox GridView
Asked by
Ian
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or