New to Telerik UI for WPF? Download free 30-day trial

Scroll to Top of WPF RadGridView after Page Change

Environment

Property Value
Product RadGridView for WPF
Version 2024.1.130

Description

How to automatically scroll to the top of RadGridView when changing a page in the associated RadDataPager.

Solution

To scroll to the top of the GridView, you can use the ScrollItemIntoView method of RadGridView or the ScrollToTop method of the GridViewScrollViewer in the PageIndexChanged event handler of RadDataPager.

The following code snippets show the two approaches:

ScrollItemIntoView example

private void RadDataPager_PageIndexChanged(object sender, Telerik.Windows.Controls.PageIndexChangedEventArgs e) 
{ 
    // the dispatcher delays the ScrollIntoView call 
    Dispatcher.BeginInvoke(new Action(() => 
    { 
        if (this.gridView.Items.Count > 0) 
        { 
            this.gridView.ScrollIntoView(this.gridView.Items[0]); 
        } 
    })); 
} 

ScrollToTop example

private void RadDataPager_PageIndexChanged(object sender, Telerik.Windows.Controls.PageIndexChangedEventArgs e) 
{ 
    var scrollViewer = this.gridView.FindChildByType<GridViewScrollViewer>(); 
    if (scrollViewer != null) 
    { 
        scrollViewer.ScrollToTop(); 
    } 
} 
In this article