Answer the question
In order to leave comments, you need to log in
How to bind table data to combobox?
Good afternoon, there are 2 tables in the database, they are presented in the project like this:
public class Employee
{
public int Id { get; set; }
public string Surname { get; set; }
public string Name { get; set; }
public string Patronymic { get; set; }
public DateTime BirthDate { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public int TitleId { get; set; }
public Title Title { get; set; }
}
public class Title
{
public int Id { get; set; }
[Column("Title")]
[NotMapped]
public string Name { get; set; }
public List<Employee> Employees { get; set; }
}
<DataGridComboBoxColumn ItemsSource="{Binding ListTitles}"
DisplayMemberPath="Name"
SelectedValuePath="{Binding Path=TitleId}"
Header="Должность"/>
Answer the question
In order to leave comments, you need to log in
All right, although you might prefer the standard ComboBox over the
DataGridComboBoxColumn :
<DataGridTemplateColumn Header="Должность">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox
HorizontalContentAlignment="Center"
ItemsSource="{Binding DataContext.Titles, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
SelectedItem="{Binding Title}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question