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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:08:26+00:00 2026-05-25T01:08:26+00:00

I have a .Net 4.0 WPF application using a data grid. Currently after sorting

  • 0

I have a .Net 4.0 WPF application using a data grid. Currently after sorting by a column, the scroll position of the grid stays where it was before the sort.

For this application, I need to scroll to the top of the grid after any sort.

I’ve tried handling the sorting event like this

    Private Sub myDataGrid_Sorting(sender As Object, e As System.Windows.Controls.DataGridSortingEventArgs) Handles myDataGrid.Sorting
            myDataGrid.ScrollIntoView(myDataGrid.Items(0))
    End Sub

But this appears to fire before the sorting takes place and doesn’t perform the scroll.

Thoughts?

  • 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-25T01:08:27+00:00Added an answer on May 25, 2026 at 1:08 am

    I don’t know the syntax in VB, but I think it should be about the same. Here it is in C#:

    var border = VisualTreeHelper.GetChild(myDataGrid, 0) as Decorator;
    if (border != null)
    {
        var scrollViewer = border.Child as ScrollViewer;
        scrollViewer.ScrollToTop();
    }
    

    Usually, the first Visual child of a DataGrid is its decorator, and the child of the decorator is the ScrollViewer. From the ScrollViewer, you can manipulate what items are shown in the dataGrid.

    Oh… And the VisualTreeHelper help you navigate from one visual element to the next inside or outside the current one you’re in. It’s in System.Windows.Media I think.

    Hope this helped. Cheers

    Edit: One other thing I forgot to mention before I posted this…
    You might need to override the OnSorting method in the DataGrid.

    So in some derived class from DataGrid of yours that will be implementing this new functionality, you’d have this override.

    protected override void OnSorting(DataGridSortingEventArgs eventArgs)
    {
        base.OnSorting(eventArgs);
    
        var border = VisualTreeHelper.GetChild(myDataGrid, 0) as Decorator;
        if (border != null)
        {
            var scrollViewer = border.Child as ScrollViewer;
            scrollViewer.ScrollToTop();
        }
    }
    
    • 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 using Fluent NHibernate 1.0 RTM and System.Data.SQLite 1.0.65 that
I have a .NET application, which is using an open source C++ compression library
I'm starting to develop a Desktop application using WPF (.net 3.5 sp1, with VS
I have a C# WPF application that needs to consume data that is exposed
I have a C# (2008/.NET 3.5) class library assembly that supports WPF (based on
I have a mixed UI (Win App, WPF App, and soon an ASP.NET MVC
Ok another WPF question, well I guess this is just general .NET. I have
I have a .Net desktop application with a TreeView as one of the UI
I have a .NET 2.0 application that has recently had contributions that are Service
I'm relatively new to .Net 4 and I am creating my FIRST WPF application

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.