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

GridViewComboBoxColumn doesn't remain selected

5 Answers 96 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Fred
Top achievements
Rank 1
Fred asked on 04 Dec 2009, 10:50 PM
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> 

5 Answers, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 09 Dec 2009, 02:55 PM
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.
0
Fred
Top achievements
Rank 1
answered on 10 Dec 2009, 03:18 PM
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.
0
Pavel Pavlov
Telerik team
answered on 14 Dec 2009, 02:39 PM
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.
0
Marc Roussel
Top achievements
Rank 2
answered on 15 Apr 2010, 02:48 PM
This helps
0
Parvinder Singh
Top achievements
Rank 1
answered on 03 Sep 2010, 09:52 AM
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.
Tags
GridView
Asked by
Fred
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Fred
Top achievements
Rank 1
Marc Roussel
Top achievements
Rank 2
Parvinder Singh
Top achievements
Rank 1
Share this question
or