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

  • Home
  • SEARCH
  • 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 6942415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:00:49+00:00 2026-05-27T13:00:49+00:00

I have a WPF application in which I use entity framework with mysql connector/net

  • 0

I have a WPF application in which I use entity framework with mysql connector/net to obtain data back. I have a combobox which is filled with items from a table. A datagrids itemssource property is binded to the combobox’ selecteditem.staff property, which displays the data correctly. The problem is that I am unable to sort this data. If I bind the data directly to the datagrid, the sorting works correctly. However if I bind the data to the combobox, then bind the datagrid to the selected item of the grid, the sorting is lost.

Entity Framework Data Retrieval

    private void RefreshOffices()
    {
        try
        {
            using (var context = new LDC_Entities())
            {
                cmbOffice.ItemsSource = context.Offices.Include("Staff.Roles").Include("Manager").ToList();
            }
        }
        catch (Exception eX)
        {
            MessageBox.Show(String.Format("Unable to retrieve offices\nError:{0}", eX.Message),"Error",
                MessageBoxButton.OK, MessageBoxImage.Error);
        }
    }

XAML Binding

<ComboBox Name="cmbOffice" Width="150" SelectedIndex="0">
<ComboBox.ItemTemplate>
    <DataTemplate>
        <TextBlock>
            <TextBlock.Text>
              <MultiBinding StringFormat="{}({0}) - {1}">
                <Binding Path="Office_ID"/>
                <Binding Path="City"/>
              </MultiBinding>
            </TextBlock.Text>
        </TextBlock>
    </DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

<DataGrid Grid.Row="1" Margin="10,50,10,10" Name="displayGrid" IsReadOnly="True" AutoGenerateColumns="False" 
      ItemsSource="{Binding ElementName=cmbOffice, Path=SelectedItem.Staff}">
<DataGrid.Columns>
    <DataGridTextColumn Header="Staff ID" Binding="{Binding Staff_ID}"/>
    <DataGridTextColumn Header="Name" Width="120" Binding="{Binding Full_Name}" />
    <DataGridTextColumn Header="Address" Width="140" Binding="{Binding Address}" />
    <DataGridTextColumn Header="DOB" Width="80" Binding="{Binding DOB, StringFormat={}{0:dd/MM/yyyy}}" />
    <DataGridTextColumn Header="Telephone" Width="100" Binding="{Binding Telephone}" />
    <DataGridTextColumn Header="Roles" Width="*" Binding="{Binding RolesList}" />
</DataGrid.Columns>
</DataGrid>

Any help would be much appreciated, I have tried playing with the CanUserSort property of the datagrid to no success. I believe it is to do with how the datagrid is filled not by the selected item, but by the .staff collection of staff members.

Thanks in advance,
Mike

  • 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-27T13:00:49+00:00Added an answer on May 27, 2026 at 1:00 pm

    First I would try to specify binding direction with Mode for DataGrid, like this

    <DataGrid Grid.Row="1" Margin="10,50,10,10" Name="displayGrid" IsReadOnly="True" AutoGenerateColumns="False" 
          ItemsSource="{Binding ElementName=cmbOffice, Path=SelectedItem.Staff, Mode=OneWay}">
    <DataGrid.Columns>
    

    if this doesn’t work for you, another solution could be:

    First bind SelectedItem of the combo to a property, DataGrid bind to another collection.
    On combo binded change, populate DataGrid‘s binded collection with sorted data.

    Hope this helps.

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

Sidebar

Related Questions

I have a WPF application in which I'm trying to use Entity Framework 4.1
I have a very simple WPF application in which I am using data binding
I have a WPF application targetting the .NET 4.0 Client Profile which needs to
I have a WPF-application with a MediaElement which I use to run a video.
I have a client application (WPF, C#, .net4) which uses POCO entity model connected
We have a WPF application which gets data from an Analysis Services Cube. The
I am working on WPF application which uses Entity Framework alongwith POCO classes. I
I am writing my first WPF application. I have also installed Entity Framework (EF)
I wrote a simple VS2010 WPF application which targeted .NET Framework 4 Client Profile
I am trying to use MVVM in my WPF application which displays data from

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.