I have a simple problem connecting an entity with a datagrid in wpf.
I have an object called "User" .... and each "User" has one "Workgroup" .. the relationship between them is one to one.
Now in EF, each user object has within it one object of the workgroup.
when I want to bind a user collection to a datagrid, I don't have a hint to say that you need to put forexample workgroup.Title inside the datagrid column
I am trying to link 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: Created a property similar to this:
public List<User> Users { get { return dal.GetUsers(); } }
and bind:
private void BindGrid() { dgUserList.ItemsSource = Users; }
this work file with direct User Entity properties, but it puts the type of the Workgroup object inside the datagrid column, and the reason is obvious. I want to put the name of the working group inside
how can i achieve this
any help would be greatly appreciated
source share