I have a simple problem binding an entity to datagrid in wpf.
I have an entity Called "User".... and each "User" have one "Workgroup" .. the relationship between the two is one to one.
now in EF every User entity has one workgroup entity inside.
when I want to bind Users Collection to datagrid I have no clue hot to say that you have to put forexample workgroup.Title inside a datagrid Column
I'm trying to bind in this way :
XAML:
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Users}" HorizontalAlignment="Stretch" Margin="5" Name="dgUserList" VerticalAlignment="Stretch" SelectionChanged="dgUserList_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding FirstName}" Header="FirstName" />
<DataGridTextColumn Binding="{Binding LastName}" Header="LastName" />
<DataGridTextColumn Binding="{Binding Username}" Header="UserName" />
<DataGridTextColumn Binding="{Binding WorkGroup}" Header="Workgroup" />
</DataGrid.Columns>
</DataGrid>
Code Behind : Created a property like this :
public List<User> Users
{
get { return dal.GetUsers(); }
}
and do the binding :
private void BindGrid()
{
dgUserList.ItemsSource = Users;
}
this work file with direct properties of User Entity but it puts type of Workgroup entity inside the datagrid column and the reason is obvious. I want to put the Title of workgroup inside
how can i achive this ?
any help would be greatly appreciated