This is a migrated thread and some comments may be shown as answers.

Handling SelectionChanged for GridViewComboBoxColumn

5 Answers 956 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eva
Top achievements
Rank 1
Eva asked on 28 May 2015, 01:55 PM

Hi,

I am trying to set a method to be called when the selected value of a GridViewComboBoxColumn is changed.

I have read about it on http://docs.telerik.com/devtools/wpf/controls/radgridview/columns/how-to/selectionchanged-comboboxcolumn and tried to implement it.

Here is my code:

mainGridView.AddHandler(RadComboBox.SelectionChangedEvent, new System.Windows.Controls.SelectionChangedEventHandler(OnSelectionChanged));
 
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
       {
           RadComboBox combo = (RadComboBox)sender;
         
              //  method to call
       }

 

However, I am getting an error:

"Expected a method with 'void OnSelectionChanged(object, SelectionChangedEventArgs signature".

If I get rid of my OnSelectionChanged() method and use the suggestions given, it gives me:

 

public System.Windows.Controls.SelectionChangedEventHandler OnSelectionChanged { get; set; }

 

Can someone please explain why this is not working for me?

Thank you

 

5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 01 Jun 2015, 10:53 AM
Hello Eva,

I subscribed to the SelectionChanged event of RadComboBox with the exact same code that you are using, and I am not able to reproduce such error. Please check the attached sample project and let me know if I am missing something.

Note also, that in the event handler arguments, "sender" is RadGridView, so in order to get the editor, which is RadComboBox, you can use the OriginalSource property of the SelectionChangedEventArgs:
var combo = e.OriginalSource as RadComboBox;

Best Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Eva
Top achievements
Rank 1
answered on 01 Jun 2015, 01:02 PM

I realized that I was trying to put the code in the ViewModel instead of the code behind. It is now working beautifully.

Thanks for your help!

 

0
Anish
Top achievements
Rank 1
answered on 29 Jun 2018, 12:54 PM
How can i achieve this using mvvm?? I have a radcombobox inside a radgridview and i need the selection changed event in my viewmodel..also is there any way I can get the previously selelcted and newly selected values from the radcombobox...plz reply 
0
Stefan
Telerik team
answered on 02 Jul 2018, 01:45 PM
Hello Anish,

In case your setup consists of having a RadComboBox inside the CellTemplate of a RadGridView's column, you can benefit from the EventToCommand behavior. Can you please take a look at the referred article?

I hope this helps.

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Mario
Top achievements
Rank 1
Iron
answered on 01 Sep 2022, 06:18 PM

Hi,

Add CellEditEnded EventTrigger to your RadGridView and bind it to a conmand in your ViewModel.

In VIew:

<telerik:RadGridView x:Name="MyRadGridView">

                   <i:Interaction.Triggers>
                                <i:EventTrigger EventName="CellEditEnded">
                                    <i:InvokeCommandAction Command="{Binding MyRadGridViewCellEditEndedHandlerCommand}"
                                        CommandParameter="{Binding ElementName=MyRadGridView}" />
                                </i:EventTrigger>
                   </i:Interaction.Triggers>

</telerik:RadGridView>

 

In ViewModel:

public Class MyViewModel : ViewModelBase, IViewModelInitialization {

    public RelayCommand<RadGridView> MyRadGridViewCellEditEndedHandlerCommand{ get; private set; }

    public MyViewModel () {

            this.MyRadGridViewCellEditEndedHandlerCommand=
                new RelayCommand<RadGridView>(this.MyRadGridViewCellEditEndedHandler);

    }

     private void MyRadGridViewCellEditEndedHandler(DataControl obj)
     {
            var selectedItem = (<<Your ObjectClass of RadGridViewRow item>>) obj.SelectedItem;
            // selectedItem includes the changes to the GridViewComboBoxColumn
     }

}


Tags
GridView
Asked by
Eva
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Eva
Top achievements
Rank 1
Anish
Top achievements
Rank 1
Mario
Top achievements
Rank 1
Iron
Share this question
or