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
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
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!
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
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
}
}