Get the selectedItem of a GridViewComboBoxColumn

12 posts, 1 answers
  1. Christophe
    Christophe avatar
    16 posts
    Member since:
    May 2014

    Posted 11 Jun 2014 Link to this post

    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 !
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 12 Jun 2014 Link to this post

    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.
     
  3. Christophe
    Christophe avatar
    16 posts
    Member since:
    May 2014

    Posted 12 Jun 2014 Link to this post

    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.
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 12 Jun 2014 Link to this post

    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.
     
  5. Christophe
    Christophe avatar
    16 posts
    Member since:
    May 2014

    Posted 12 Jun 2014 in reply to Dimitrina Link to this post

    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.
  6. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 12 Jun 2014 Link to this post

    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.
     
  7. Christophe
    Christophe avatar
    16 posts
    Member since:
    May 2014

    Posted 12 Jun 2014 Link to this post

    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 ?
  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 13 Jun 2014 Link to this post

    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.
     
  9. Christophe
    Christophe avatar
    16 posts
    Member since:
    May 2014

    Posted 13 Jun 2014 Link to this post

    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 !
  10. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 13 Jun 2014 Link to this post

    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.
     
  11. Christophe
    Christophe avatar
    16 posts
    Member since:
    May 2014

    Posted 13 Jun 2014 Link to this post

    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 !
  12. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Jun 2014 Link to this post

    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.
     
Back to Top