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

Get the selectedItem of a GridViewComboBoxColumn

11 Answers 220 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christophe
Top achievements
Rank 1
Christophe asked on 11 Jun 2014, 09:35 AM
Hello,

I found out that there's no such property inside the GridViewComboBoxColumn control to get the selected value. I tried a lot of things to get this value in my code but nothing worked, and I really need to use the selected value in my ComboBox since other cells will be supposed to be updated thanks to the selection.

Is there any way to do it please ?

I've two subsidiary questions : why this control doesn't contain this property like the RadComboBox, what's the point ? And, I also tried to write
((Telerik.Windows.Controls.GridViewBoundColumnBase)(editor)).OldValueReference.ToString()

And it appears that OldValueReference is unknown. I copied that from my var content, like in the pictures.

Thanks for your help !

11 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 12 Jun 2014, 11:23 AM
Hi Christophe,

You can check the Handle SelectionChanged for the GridViewComboBoxColumn article. That way you will be able to access the SelectedValue and update the other cells accordingly.

Thank you for your feedback, we will discuss your second question.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Christophe
Top achievements
Rank 1
answered on 12 Jun 2014, 11:30 AM
Hello Didie,

Unfortunately I already tried this event in my code, that's exactly where I tried to get the selected value, but I guess I didn't find the right code, everything I did never worked, I was just able to get the type of the column.

Thanks for your time.
0
Dimitrina
Telerik team
answered on 12 Jun 2014, 02:39 PM
Hello,

You can get the last selected value in the editor (RadComboBox) like so:
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (e.RemovedItems.Count > 0)
    {
        if (e.AddedItems.Count > 0)
        {
            var selectedValue = e.AddedItems[0];
        }
    }
}

How does this work for you?

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Christophe
Top achievements
Rank 1
answered on 12 Jun 2014, 03:16 PM
Hello,

Thanks for your answer but it doesn't work. First, I had to delete the first if condition, else it never goes inside. And then, a MessageBox with a toString() method displays "System.Data.DataRowView", but not the selectedValue as expected. I tried some things with the SelectionChangedEventArgs, nothing worked.

Thanks.
0
Accepted
Dimitrina
Telerik team
answered on 12 Jun 2014, 03:41 PM
Hello,

You can see DataRowView as this is the entire bound item (as the ItemsSource of the GridViewComboBoxColumn is set to DataTable.DefaultView), so this is the SelectedItem and not the SelectedValue.

You can use this code to directly access the selected value (the value displayed in the RadComboBox as you selected it):
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (e.RemovedItems.Count > 0)
    {
        var selectedValue = (e.OriginalSource as RadComboBox).SelectedValue;
    }
}

I hope this helps.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Christophe
Top achievements
Rank 1
answered on 12 Jun 2014, 03:48 PM
Hello,

Thank you for your answer, it works perfectly (except the if condition which doesn't work at all) !

Any reason why I can't get this value as easily as writing .selectedValue ?
0
Dimitrina
Telerik team
answered on 13 Jun 2014, 08:15 AM
Hi,

I am glad to hear this works fine for you.
The SelectedValue in the GridViewComboBoxColumn is actually represented by the specified DataMemberBinding for it. Therefor you can also get this value from the respective data item.
You can check our online documentation on ComboBox Column for a better understanding on how the column works.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Christophe
Top achievements
Rank 1
answered on 13 Jun 2014, 10:27 AM
Hello,

Ok I think I see what you mean... It could be a good point if this method was added in your documentation.

However, I tried to get the selected value in order to update another GridViewComboBoxColumn, but it always throws me an OutOfRangeException.

For instance, if I select "AAA" in the first GridViewComboBoxColumn, the second GridViewComboBoxColumn should have 1, 2 and 3 inside ; if I select "BBB" in the first, the seconde one should have 4, 5 and 6 inside. So I tried to update my ObservableCollection but it raises this exception when I want to .Clear() it before to .Add() my new elements. I guess I can't update a bounded list, so what's the solution to do so ?

By default, my ObservableCollection is filled with "1, 2, 3, 4, 5, 6" since nothing is selected in the first GridViewComboBoxColumn.

Thank you again !
0
Dimitrina
Telerik team
answered on 13 Jun 2014, 01:43 PM
Hello,

Is the exception raised as you .Cleart() the collection or is it raised when you are trying to Add a new item?
Would it be possible for you to isolate the issue in a sample project and send it to me? You can take a look at this blog post for a reference on how to isolate an issue. 

You can then open a new support thread and attach the project there.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Christophe
Top achievements
Rank 1
answered on 13 Jun 2014, 02:33 PM
Hello,

It happens when I try to Clear my list. I've posted another thread with a link to my project here : http://www.telerik.com/forums/clear-itemssource-raises-outofrangeexception

Thanks !
0
Dimitrina
Telerik team
answered on 17 Jun 2014, 11:37 AM
Hi,

Thank you for sending a demo solution. I have answered in the other thread.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Christophe
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Christophe
Top achievements
Rank 1
Share this question
or