Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:55:50+00:00 2026-05-23T16:55:50+00:00

I have a simple problem binding an entity to datagrid in wpf. I have

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:55:51+00:00Added an answer on May 23, 2026 at 4:55 pm

    WPF Bindings support nested properties so to get to any of the sub-properties on a property of a bound object just use normal “.” syntax:

    <DataGridTextColumn Binding="{Binding WorkGroup.Title}" Header="Workgroup" />
    

    You also don’t need to set the ItemsSource twice. If you have the DataContext of the DataGrid set up as the Window (or UserControl, etc.) whose code-behind declared the Users property then the ItemsSource Binding in XAML is sufficient and you can remove the BindGrid method. If you haven’t set the DataContext, the XAML ItemsSource Binding isn’t doing anything (you can probably see an error message in your Debug Output) so you can remove that and just let the code-behind method take care of it.

    You should also consider using an ObservableCollection to get automatic notification and UI updates when items are added or removed. Since you’re already using EF you may also be able to just use the EntityCollection for User, which includes the same automatic INotifyCollectionChanged notification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a seemingly simple problem whereby I wish to reconcile two lists so
I have a very simple binding problem with a DatePicker that is eluding me.
I have a simple problem when querying the SQL Server 2005 database. I have
i have very simple problem. I need to create model, that represent element of
I have a simple problem that i cannot solve. I have a dictionary: aa
I have a simple problem but I am not sure how to solve it.
I have a simple problem but no matter what I try I can't see
I have a very simple problem which requires a very quick and simple solution
I have a very simple problem and a solution that will work, but I'm
I have a seemingly simple problem though i am unable to get my head

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.