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

Programmatic Scrolling

The DataGrid exposes methods for programmatic scrolling for a specific column, a specific row index, or a specific data item.

The following properties are supported:

  • ScrollColumnIntoView(DataGridColumn column)—Attempts to asynchronously bring the specified DataGridColumn into view.
  • ScrollIndexIntoView(int index)—Attempts to asynchronously bring the data item at the specified zero-based index into view.
  • ScrollItemIntoView(object item)—Attempts to asynchronously bring the specified data item into view.

The following examples demonstrate how to use these methods in practice.

Create a RadDataGrid in XAML

<telerikGrid:RadDataGrid x:Name="DataGrid" Width="200" RowHeight="50" Height="80" /> 

Populate the DataGrid with Sample Data

public class Data 
{ 
    public string Country { get; set; } 
 
    public int Population { get; set; } 
 
    public string Capital { get; set; } 
} 
 
public MainPage() 
{ 
    this.InitializeComponent(); 
 
 
    List<Data> dataList = new List<Data> 
    { 
        new Data { Country = "Argentina", Population = 41300000, Capital = "Buenos Aires" }, 
        new Data { Country = "France", Population = 65350000, Capital = "Paris" }, 
        new Data { Country = "Japan", Population = 26700000, Capital = "Tokyo" }, 
        new Data { Country = "Spain", Population = 47300000, Capital = "Madrid" }, 
        new Data { Country = "Germany", Population = 82000000, Capital = "Berlin" }, 
        new Data { Country = "Egypt", Population = 90000000, Capital = "Cairo" }, 
        new Data { Country = "Bulgaria", Population = 7500000, Capital = "Sofia" }, 
        new Data { Country = "Switzerland", Population = 8000000, Capital = "Bern" }, 
        new Data { Country = "Canada", Population = 33500000, Capital = "Ottawa" }, 
        new Data { Country = "Russia", Population = 143300000, Capital = "Moscow" }, 
        new Data { Country = "Denmark", Population = 5600000, Capital = "Copenhagen" }, 
    }; 
    this.DataGrid.ItemsSource = dataList; 
} 

Apply Programmatic Scrolling

// Scroll (bring into View) to the third column of the DataGrid. 
this.DataGrid.ScrollColumnIntoView(this.DataGrid.Columns[2]); 
 
// Scroll (bring into View) to the twelfth row of the DataGrid. 
this.DataGrid.ScrollIndexIntoView(11); 
 
// Scroll (bring into View) to a specific data item from the data. 
this.DataGrid.ScrollItemIntoView(dataList[6]); 
In this article
Not finding the help you need?