Hi all:
I'm new in WPF and I'm having a hard time trying to make the Combobox works in a DataGridTemplateColumn. I don't want to use DatagridComboboxColumn because the cells on this column look like a text column, the user has to click on it so the arrow down shows up.
I'm able to populate the Combobox but when I select a value from any row, it changes to all the rest of the cells in the Datagrid. What am I doing wrong? Hope you can help me, please.
Thanks in advance.
.cs
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LoadEmployee();
}
public List<GenderList> GenderList { get; set; }
void LoadEmployee()
{
GenderList = new List<GenderList>()
{
new GenderList() { Codigo = 100, Descripcion = "MALE" },
new GenderList() { Codigo = 200, Descripcion = "FEMALE"; }
};
Employees = new List<Employee>()
{
new Employee() {Codigo = 1, Name = "CARLOS", Gender = "MALE", Birthday = new DateTime(1971, 7, 23)},
new Employee() {Codigo = 2, Name = "ANDREA", Gender = "FEMALE", Birthday = new DateTime(1971, 7, 23)},
new Employee() {Codigo = 3, Name = "JOSE", Gender = "FEMALE", Birthday = new DateTime(1971, 7, 23)},
new Employee() {Codigo = 4, Name = "CHICHI", Gender = "FEMALE", Birthday = new DateTime(1971, 7, 23)},
new Employee() {Codigo = 5, Name = "MILU", Gender = "FEMALE", Birthday = new DateTime(1971, 7, 23)},
new Employee() {Codigo = 6, Name = "MIA", Gender = "FEMALE", Birthday = new DateTime(1971, 7, 23)}
};
dglist.ItemsSource = Employees;
var cvs = (FindResource("StatusItems") as CollectionViewSource);
cvs.Source = GenderList;
}
public class Employee
{
public int Codigo { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public DateTime Birthday { get; set; }
}
.xaml
<Window.Resources>
<CollectionViewSource x:Key="StatusItems"/>
</Window.Resources>
.
.
.
<DataGridTemplateColumn Header="Combo">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox BorderThickness="0"
ItemsSource="{Binding Source={StaticResource StatusItems}}"
SelectedValue="{Binding GenderList, UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Descripcion"
SelectedValuePath="Codigo"
/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>