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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:01:33+00:00 2026-06-02T16:01:33+00:00

I have a WPF DataGrid that in its first column holds a number that

  • 0

I have a WPF DataGrid that in its first column holds a number that is the “ranking” or “position”. What I want is that when I click on a column to sort the table based on that column, for the first column to stay as-is.

For example:

Position  Name   Games   Points    PPG
1         John   2       10        5
2         Mary   3       12        4

when sorted by Games in descending order should become

Position  Name   Games   Points    PPG
1         Mary   3       12        4
2         John   2       10        5

Is there a way to do this? DataColumn doesn’t seem to have any such property, and FreezeColumnsCount only retains them in view at all times, but doesn’t stop them from being sorted along with the rest of the data.

  • 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-06-02T16:01:34+00:00Added an answer on June 2, 2026 at 4:01 pm

    In http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/ffd7037d-dd77-44ec-9011-d0d43d5706aa/ I just found an example (answer from Adbie) for what I suggested in my comment:

    <DataGrid LoadingRow="dg_LoadingRow">
        <DataGrid.RowHeaderTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Path=Header, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" />
            </DataTemplate>
        </DataGrid.RowHeaderTemplate>
    </DataGrid>
    

    private void dg_LoadingRow(object sender, DataGridRowEventArgs e)
    {
        e.Row.Header = (e.Row.GetIndex() + 1).ToString();
    }
    

    EDIT by OP:
    I’ve just verified it works even without the binding. The cs code is fine, but in XAML you only need to do

    <DataGrid LoadingRow="dg_LoadingRow" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to achieve the following: Create a WPF DataGrid that have 2 columns:
I have a WPF DataGrid that will be populated from a data table having
I have a DataGrid in WPF app with several columns, including a Name column.
I have a DataGrid in a WPF application which has for its ItemsSource a
I have a WPF Datagrid and its integer datatype columns are editable and hence
I have a wpf datagrid that has it's columns generated dynamically in code and
I have an ObservableCollection that is bound to a DataGrid where I want the
I'm experimenting with databinding in WPF I have this datagrid that is bound to
I have a WPF DataGrid templatecolumn that has a DataTemplate for an AutoCompleteBox from
I have a WPF DataGrid which displays types that implement IDataErrorInfo. As expected when

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.