Articles in this section
Category / Section

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

2 mins read

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

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied