GridViewComboBoxColumn doesn't remain selected

6 posts, 1 answers
  1. Fred
    Fred avatar
    86 posts
    Member since:
    Sep 2008

    Posted 04 Dec 2009 Link to this post

    Has anyone else seen where if you use a GridViewComboBoxColumn in a datagrid, when you make a selection and click on another row, it goes back to being unselected? None of the selected values stick.

                    <telerikGridView:RadGridView  
                    x:Name="gvHeaders"  
                    ShowGroupPanel="False"  
                    Margin="33,145,0,59"  
                    CanUserReorderColumns="False" 
                    CanUserInsertRows="False" 
                    CanUserSortColumns="False"  
                    HorizontalAlignment="Left" 
                    AutoGenerateColumns="False" 
                    IsReadOnly="False" 
                    Foreground="Black" 
                    CanUserSelect="True" Background="{x:Null}" 
                    > 
                        <telerikGridView:RadGridView.Columns> 
                            <telerikGridView:GridViewDataColumn  
                            Header="Your Import Headers"  
                            UniqueName="ImportHeaders"  
                            IsReadOnly="True"  
                            Background="{x:Null}" 
                            DataMemberBinding="{Binding Field}" /> 
                            <telerikGridView:GridViewComboBoxColumn  
                            Header="System Fields"  
                            UniqueName="SystemFields"  
                            Background="{x:Null}" 
                            DataMemberBinding="{Binding ImportSystemFields}" 
                            SelectedValueMemberPath="DataFieldName" 
                            DisplayMemberPath="DisplayName" /> 
                        </telerikGridView:RadGridView.Columns> 
                    </telerikGridView:RadGridView> 

  2. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 09 Dec 2009 Link to this post

    Hello Fred,

    When RadGridView sets the cell value it performs a search in the ItemsSource of the ComboBoxColumn and tries to find an exact match to the value of the cell.

    The behavior you describe is typically a result of the fact RadGridView can not match a value in the ItemsSource of the combo with the value in the cell.
    (the match uses the Equals() method) .  Typically such problem occurs when you bind to a custom object rather than a primitive property e.g. you use a list of Country objects instead of list of integer Country ID's. A possible solution may be to override the Equals() in the country object, or use the same instances so that they can match.

    If all that sounds messy , you are always welcome to send me your project in a support ticket and I will gladly make the modifications necessary.

    All the best,

    Pavel Pavlov
    the Telerik team

     


    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Fred
    Fred avatar
    86 posts
    Member since:
    Sep 2008

    Posted 10 Dec 2009 Link to this post

    Hmm, ok makes sense, except, I guess this is a basic silverlight question, but how the heck then do you give your grid a datasource that has no "country id's" and you want to use the dropdown to select the country id and set it, twoway bind.  If it has no value to match shouldn't it set it to the value of the selected value in the combobox?  I realize this isn't a telerik issue as I used regular combobox and had the same problem.
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 14 Dec 2009 Link to this post

    Hi Fred,

    I believe we can cover most of the common lookup scenarios with  RadGridViewComboboxColumn .
    Can you please describe me  your data model and I will try to provide a working sample.
    What I need to know is the structure of the data in the RadGridView.ItemsSource,
    the structure of the data in the ComboBoxColumn.ItemsSource and in a few words  - the way you expect it to behave.

    Meanwhile please have a look at the attached example. It demonstrates a similar scenario.
    We have the RadGridView bound to a list of 'Location' objects.
    Each location has a Country property. We do not store the ID of the country , but the whole country object ( as requested)  instead.
    The combo box displays a list of Countries and the column displays the selected country .


    Sincerely yours,

    Pavel Pavlov
    the Telerik team

     


    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 15 Apr 2010 Link to this post

    This helps
  7. Parvinder Singh
    Parvinder Singh avatar
    10 posts
    Member since:
    Mar 2010

    Posted 03 Sep 2010 Link to this post

    My requirement is something like following code :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Telerik.Windows.Controls;

    namespace TwoWayBoundComboColumn
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                this.Countries = new List<Country>();

                Countries.Add(new Country() { ID = 0, Name = "USA" });
                Countries.Add(new Country() { ID = 1, Name = "Italy" });
                Countries.Add(new Country() { ID = 2, Name = "Germany" });


                this.RadGridView1.ItemsSource = GetLocations();
                ((GridViewComboBoxColumn)this.RadGridView1.Columns[0]).ItemsSource = this.Countries;
            }

            public List<Country> Countries
            {
                get;
                set;
            }

            private List<Location> GetLocations()
            {
                List<Location> locations = new List<Location>();

                locations.Add(new Location() { ID = 1, CountryID =3 });
                locations.Add(new Location() { ID = 2, CountryID = 1 });
                locations.Add(new Location() { ID = 3, CountryID = 2 });

                return locations;
            }
        }

        public class Location
        {
            public int ID{get; set;}
            public int CountryID { get; set; }
        }

        public class Country
        {
            public int ID { get; set; }
            public string Name { get; set; }
        }
    }

    Please reply.
Back to Top
DevCraft banner