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 1100225
In Process

The Archive Base Latest Questions

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

I have a TabControl where each tab contains a DataGrid . When the user

  • 0

I have a TabControl where each tab contains a DataGrid. When the user switches between tabs it seems that the DataGrid is created from scratch. I say this becuase of three things that I’ve noticed: the columns are automatticaly recreated, the current sorted column is lost, and selection is lost.

I would love to be able to retain the current sorted view when the user returns to a tab page. They may be comparing lists and it doesn’t make sense to have them resort each time. The databehind the scenes is not changing once it is created. However, the the tabs are bound to an observable collection because they need to be added/removed depending on how the application is being used.

ViewModel:

public ObservableCollection<DataTable> Tables
{
    get
    {
        return _tables; // Tables are added/removed through secondary methods
    }
}

View:

<TabControl ItemsSource="{Binding Path=Tables"}>
    <TabControl.ItemTemplate>
        <DataTemplate>
            <TextBlock>
                <TextBlock.Text>
                    <MultBinding StringFormat="{}{0} ({1})}>
                        <Binding Path="TableName"/>
                        <Binding Path="Rows.Count"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </DataTemplate>
    </TabControl.ItemTemplate>
    <TabControl.ContentTemplate>
        <DataTemplate>
            <DataGrid
                AutoGeneratingColumns="True"
                IsReadOnly="True"
                ItemsSource="{Binding DefaultView}"
                />
        </DataTemplate>
    </TabControl.ContentTemplate>
</TabControl>

Is there anyway to keep the current sort order of the datagrid when tabs are changed?

  • 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-17T00:50:55+00:00Added an answer on May 17, 2026 at 12:50 am

    I think this has to do with the TabControl behavior more than the Datagrid. I may be wrong, but the TabControl only has one content area, and switches the contents when you change the selected tab, which means that the content will get recreated no matter what you do. Not sure there’s a simple workaround for this… I’d love to hear answers from more knowledgeable people.

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

Sidebar

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.