2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Scroll to a specific record in datagridYou 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.
This page will automatically be redirected to the sign-in page in 10 seconds.
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));
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.
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