How to scroll to a specific record programmatically in WinForms DataGrid?
You can programmatically scroll to a specific record in WinForms DataGrid (SfDataGrid) using the ScrollInView method. You can get the row index of any record using the 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
Conclusion
I hope you enjoyed learning how to scroll to a specific record programmatically in DataGrid.
You can refer to our WinForms DataGrid feature tour page to know about its other groundbreaking feature representations and WinForms DataGrid documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms DataGrid example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!