I have a combo box column with in the grid and i need an event for that combo box value changed .
I am unable to register a selection changed event for telerik:GridViewComboBoxColumn.
Suggest me how to do that.
Thanks,
Swathi.
14 Answers, 1 is accepted
You may add a handler for the SelectionChanged event as follows:
this.RadGridView1.AddHandler(RadComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(OnSelectionChanged));
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
// TODO: Implement this method
throw new NotImplementedException();
}
Maya
the Telerik team

1.Can i register the event for a particular column in a grid.right now i am putting a condition within the event.
2.This event is being called while loading also,which i think is not valid.Can u answer this?
Thanks in advance
You need to define a condition in the OnSelectionChanged method if you want to fire the event only for a particular column. For example:
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
//First approach:
var cell = (e.OriginalSource as RadComboBox).ParentOfType<
GridViewCell
>();
if (cell != null && cell.Column.UniqueName == "MyUniqueName")
{
}
//Second approach:
RadComboBox comboBox = (RadComboBox)e.OriginalSource;
if (comboBox.SelectedValue == null || comboBox.SelectedValuePath != "Code") // we take action only if the continent combo is changed
{
}
}
As for your second question, indeed the event is fired while loading and so far this is the expected behavior. Greetings,
Maya
the Telerik team

Cheers
he idea of the logic implemented should be exactly the same as in C#. Could you clarify what are the difficulties you met when writing the code in VB ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

this.RadGridView1.AddHandler(RadComboBox.SelectionChangedEvent,
new SelectionChangedEventHandler(OnSelectionChanged));
The converter gives you this:
Me.RadGridView1.[AddHandler](RadComboBox.SelectionChangedEvent, New SelectionChangedEventHandler(OnSelectionChanged))
As with all addhandler conversions it is wrong, I have worked out how to modify a normal handler using the address of function but I cannot work out the syntax for how to handle one that is bound to a grid, it comes up with errors like, cannot use a lamda expression, must use addressof and radcombobox has no such event..
Cheers
You can take a look at this forum thread for further reference.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Error 3 Method 'Private Sub comboSelectionChanged(sender As Object, e As Telerik.Windows.RadRoutedEventArgs)' does not have a signature compatible with delegate 'Delegate Sub SelectionChangedEventHandler(sender As Object, e As Telerik.WinControls.UI.SelectionChangedEventArgs)'. C:\TFS_Trunk\BM Pallets\EMU\dashboard\admin\ucAdminAddresses.xaml.vb 29 101 dashboard
My other issue here is that I have spent countless hours as a VB developer trying to find work arounds to the c# code samples and documentation. Surely you as a company selling these controls for the same price as the c# users should provide equal documentation for both instead of making us VB users scrounge around in blog posts hoping that someone else has had the same issue previously. Just today I have wasted 2 hours on this and I've been having these same issues for around 3 years now, it equates to 'days' lost...!

Thank you for sharing your feedback.
For the VB programmers we offer this online converter. For the purpose of converting entire solutions, you can also consider using Instant VB Converter.
Also, as you run the WPF demos, the C# code can be converted into VB.NET code on demand (choosing the VB.NET tab for the code behind files).
Regards,
Dimitrina
Telerik

I'm trying to add selectioin changed event in my GridViewComboboxColumn.
But, AddHandler does not exist.
I'm using Telerik UI for WinForms R2 2017 SP1.
The AddHandler() method is part of the WPF framework. If you need to subscribe to a handler in WinForms I would suggest you take a look at the MSDN docs.
Also, if for any questions related with Telerik UI for WinForms may I ask you to post your question in the WinForms forum or via the support ticketing system.
Regards,
Martin Ivanov
Progress Telerik

I found this information helpful .. But I was wondering if it was possible to add the Even handler in XAML
Thanks
The event handler cannot be attached in XAML in this scenario. This is because the column doesn't expose the corresponding event. The AddHandler() method is used to globally attach the handler to all selector elements that expose SelectionChanged event.
An alternative approach to subscribe to the SelectioChanged event is to create a custom combobox column and override its CreateCellEditElement. There you can get the RadComboBox element and subscribe to its SelectionChanged event. Then raise a new custom event that you can use. Here is an example in code:
public
class
CustomGridViewComboBoxColumn : GridViewComboBoxColumn
{
public
event
EventHandler<SelectionChangedEventArgs> SelectionChanged;
public
override
FrameworkElement CreateCellEditElement(GridViewCell cell,
object
dataItem)
{
var comboBox = (RadComboBox)
base
.CreateCellEditElement(cell, dataItem);
comboBox.SelectionChanged += OnComboBoxSelectionChanged;
return
comboBox;
}
private
void
OnComboBoxSelectionChanged(
object
sender, SelectionChangedEventArgs e)
{
if
(SelectionChanged !=
null
)
{
SelectionChanged(
this
, e);
}
}
}
<
telerik:RadGridView.Columns
>
<
local:CustomGridViewComboBoxColumn
SelectionChanged
=
"CustomGridViewComboBoxColumn_SelectionChanged"
/>
</
telerik:RadGridView.Columns
>
Regards,
Martin Ivanov
Progress Telerik