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

ComboBox Binding

0 Answers 45 Views
GridView
This is a migrated thread and some comments may be shown as answers.
+++AAA+__WOULD BUY AGAIN ++++
Top achievements
Rank 1
+++AAA+__WOULD BUY AGAIN ++++ asked on 06 Aug 2012, 06:34 PM
Edit:
Here is the solution:

<telerik:GridViewComboBoxColumn Header="Location"
                                    DataMemberBinding="{Binding LocationId}"
                                    UniqueName="LocationId"
                                    ItemsSourceBinding="{Binding Path=Locations,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
                                    SelectedValueMemberPath="Id"
                                    DisplayMemberPath="Name" />


I am evaluating the GridView and have ran into an issue binding the domain data which represents each row  to the ComboBox in the GridView using MVVM.  The GridView  is populated with Employees.  Each employees (Employee class) has a list of locations (Locations property on the Employee class) and a SelectedLocationId.  These locations will fill the combobox in a column in the GridView.  So for example, I have two employees, each bound to the Grid:

public class MyViewModel{
 
    public BindingList<Employee> Employees { //The grid binds to this list}
}
 
public class Employee{
    public string Name{...}
    public int SelectedLocationId {...}
    public BindingList<Location> Locations {...} //Binds to combobox in grid.
//Location class has Name and Id property
}


The data:
Joe
Locations: US, Canada
SelectedLocation: Canada
Bob
Locations: US, Mexico
SelectedLocation: Mexico

One of the columns in the grid should be "Location" with a combobox column which has the respective data for each employee.  I tried this in the GridView:

     
<telerik:GridViewComboBoxColumn Header="Location"
                              ItemsSource="{Binding Path=Locations, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:GridViewRow}}"
                              DisplayMemberPath="Name"
                              FocusVisualStyle="{x:Null}"
                      SelectedValueMemberPath="Id">

However, I see in the output, that the Combobox is trying to bind to the ViewModel instead of the domain entity Employee.  How can I bind a combobox in the grid to a list on the domain entity in each row?

Thanks for your help!

No answers yet. Maybe you can help?

Tags
GridView
Asked by
+++AAA+__WOULD BUY AGAIN ++++
Top achievements
Rank 1
Share this question
or