We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to scroll to a specific record programmatically in WinForms DataGrid (SfDataGrid)?

Platform: WinForms |
Control: SfDataGrid
Tags: scrolling, row

Scroll to a specific record in datagrid

You can programmatically scroll to a specific record in DataGrid using the SfDataGrid.TableControl.ScrollRows.ScrollInView method. You can get the row index of any record using the SfDataGrid.TableControl.ResolveToRowIndex method.

In the following example, data grid is scrolled to a record with OrderID value: 10680.

C#

var record = this.sfDataGrid.View.Records.FirstOrDefault(item => (item.Data as OrderInfo).OrderID == 10680);
 
if (record != null)
{
    this.sfDataGrid.TableControl.ScrollRows.ScrollInView(this.sfDataGrid.TableControl.ResolveToRowIndex(record));
    this.sfDataGrid.TableControl.UpdateScrollBars();
}

VB

Dim record = Me.sfDataGrid.View.Records.FirstOrDefault(Function(item) (TryCast(item.Data, OrderInfo)).OrderID = 10680)
 
If record IsNot Nothing Then
 Me.sfDataGrid.TableControl.ScrollRows.ScrollInView(Me.sfDataGrid.TableControl.ResolveToRowIndex(record))
 Me.sfDataGrid.TableControl.UpdateScrollBars()
End If

Sample: How to scroll to a specific record programmatically in datagrid

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Edward Auga
Oct 05, 2019

The scroll code does work, after a fashion. It scrolls the name into view but only 1/2 of the name is visible. I resolved my code by using: ...sfDataGrid3.TableControl.ResolveToRowIndex(inx + 1));

Reply
Mohanram Anbukkarasu [Syncfusion]
Oct 07, 2019

Hi Edward,

Thanks for your update.

We have checked the reported scenario by scrolling to a specific line index by passing the index instead of the record. Unfortunately we are unable to reproduce the reported issue in our end. The specified line is fully displayed as expected.

Regards, Mohanram A.

Leigh Anderson
Apr 12, 2022

Hi - I have an issue with this method.

In one of my grids I have rows of variable height and am using a QueryRowHeight event to set the row heights.

If I then call ResolveToRowIndex() it doesn't scroll all the way to the bottom - there are still a couple of rows below the scroll point.

Without the QueryRowHeight it works fine but I need a solution where rows are different heights.

Any ideas?

Leigh

Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile