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

GridViewComboBoxColumn doesn't drop down and show values for edit.

1 Answer 115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brady
Top achievements
Rank 1
Brady asked on 21 Oct 2013, 11:31 AM
I have the following two classes:
public class Gender
{
    public int Id { getset; }
    public string Name { getset; }
}
public class Person
{
    public string Name { getset; }
    public int? GenderId { getset; }
    public bool IsActive { getset; }
}

And I have the following RadGridView, bound to an ObservableCollection<Person>, wanting to use a ComboBox to choose their gender:

<telerik1:RadGridView x:Name="Grid"                              
                        ItemsSource="{Binding Persons}"
                        IsSynchronizedWithCurrentItem="True"
                        AutoGenerateColumns="False" 
                        ShowGroupPanel="False" 
                        ShowInsertRow="True"
                        CanUserInsertRows="true">
    <telerik1:RadGridView.Columns>
        <telerik1:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" Width="*" />
        <telerik1:GridViewComboBoxColumn
                Name="Gender"
                Header="Gender"  
                DataMemberBinding="{Binding GenderId}"
                DisplayMemberPath="Name"
                SelectedValueMemberPath="Id"
                ItemsSourceBinding="{Binding Genders}"
                EditTriggers="CellClick"
                IsReadOnly="False"
                Width="80"  />
        <telerik1:GridViewCheckBoxColumn
            DataMemberBinding="{Binding IsActive}"
            Header="Active"
            IsReadOnly="False" />
    </telerik1:RadGridView.Columns>
</telerik1:RadGridView>

I followed one of Telerik's examples I found somewhere to define the Combo column, and it has values
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
 
        Genders = new ObservableCollection<Gender>
            {
                new Gender {Id = 0, Name = "Female"},
                new Gender {Id = 1, Name = "Male"},
                new Gender {Id = 2, Name = "Withheld"}
            };
 
        Persons = new ObservableCollection<Person>
            {
                new Person {Name = "Andy", GenderId = 1, IsActive = false},
                new Person {Name = "Mary", GenderId = 0, IsActive = true},
                new Person {Name = "Peta", GenderId = 2, IsActive = true},
                new Person {Name = "Gerald", GenderId = 0, IsActive = true}
            };
    }
 
    public ObservableCollection<Gender> Genders { getset; }
    public ObservableCollection<Person> Persons { getset; }
}

So, I'm convinced I'm setting properties wrong on the GridViewComboBoxColumn or setting the wrong properties. 
What is wrong with the above scenario?



1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 21 Oct 2013, 02:51 PM
Hello Brady,

Please take another look at our documentation. In this case you need to work with ItemsSource instead.  ItemsSourceBinding should be used when you have a collection property in the definition of the business object of the grid - in this case to have Genders property in Person class.

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Brady
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or