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

Selection changed event for gridviewcombobox column

14 Answers 1055 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Swathi
Top achievements
Rank 1
Swathi asked on 15 Dec 2010, 08:50 AM
Hi ,
               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

Sort by
0
Maya
Telerik team
answered on 15 Dec 2010, 09:18 AM
Hi Swathi,

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();
}

All the best,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Swathi
Top achievements
Rank 1
answered on 15 Dec 2010, 11:09 AM
Thanks for the immediate response.I am able to register and use the event now.But i have few more queries.

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
1
Maya
Telerik team
answered on 15 Dec 2010, 06:59 PM
Hello Swathi,

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
Browse the videos here>> to help you get started with RadControls for WPF
0
AndyRutter
Top achievements
Rank 2
answered on 31 Jul 2012, 08:52 AM
Please could you also provide a sample in VB, your converter is next to useless when dealing with events
Cheers
0
Maya
Telerik team
answered on 31 Jul 2012, 10:05 AM
Hello Brian,

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 ? 


Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
AndyRutter
Top achievements
Rank 2
answered on 31 Jul 2012, 10:23 AM
I have no idea how to implement the following in VB:
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
0
Maya
Telerik team
answered on 31 Jul 2012, 10:47 AM
Hi,

You can take a look at this forum thread for further reference.
 

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
AndyRutter
Top achievements
Rank 2
answered on 31 Jul 2012, 11:12 AM
Hadn't seen that blog post but I still get this error:
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...!
0
Robert
Top achievements
Rank 1
answered on 16 Jul 2015, 04:39 PM
I agree with the comment - why are vb programmers treated as 2nd class citizens by Terlerik?
0
Dimitrina
Telerik team
answered on 21 Jul 2015, 10:18 AM
Hi,

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
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
Zan
Top achievements
Rank 1
answered on 30 Sep 2017, 07:54 AM

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.

0
Martin Ivanov
Telerik team
answered on 04 Oct 2017, 06:56 AM
Hello AungKo,

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
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
Michael
Top achievements
Rank 1
answered on 01 Dec 2017, 04:06 PM

I found this information helpful .. But I was wondering if it was possible to add the Even handler in XAML

Thanks

0
Martin Ivanov
Telerik team
answered on 06 Dec 2017, 09:39 AM
Hello Michael,

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
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.
Tags
GridView
Asked by
Swathi
Top achievements
Rank 1
Answers by
Maya
Telerik team
Swathi
Top achievements
Rank 1
AndyRutter
Top achievements
Rank 2
Robert
Top achievements
Rank 1
Dimitrina
Telerik team
Zan
Top achievements
Rank 1
Martin Ivanov
Telerik team
Michael
Top achievements
Rank 1
Share this question
or