How to scroll to a specific row/column programmatically in SfDataGrid?
SfDataGrid allows you to scroll to a specific row/column programmatically. You can scroll vertically to a specific row index or horizontally to a specific column index or even diagonally to the specified row and column index.
Scroll to row index
You can scroll programmatically to a particular row index using SfDataGrid.ScrollToRowIndex method by passing row index as parameter.
public class MainActivity : Activity { Button rowScrollButton; Button columnScrollButton; Button rowColumnScrollButton; SfDataGrid dataGrid; ViewModel viewModel; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); LinearLayout layout = new LinearLayout(this); layout.SetPadding(0, 0, 10, 10); layout.Orientation = Orientation.Vertical; rowScrollButton = new Button(this); rowScrollButton.Text = "Scroll to RowIndex"; rowScrollButton.SetWidth(100); rowScrollButton.Click += RowScrollButton_Click; layout.AddView(rowScrollButton); columnScrollButton = new Button(this); columnScrollButton.Text = "Scroll to Columnindex"; columnScrollButton.SetWidth(100); columnScrollButton.Click += ColumnScrollButton_Click; layout.AddView(columnScrollButton); rowColumnScrollButton = new Button(this); rowColumnScrollButton.Text = "Scroll to RowColumnIndex"; rowColumnScrollButton.SetWidth(100); rowColumnScrollButton.Click += RowColumnScrollButton_Click; layout.AddView(rowColumnScrollButton); dataGrid = new SfDataGrid(this); viewModel = new ViewModel(); dataGrid.ItemsSource = viewModel.ProductDetails; layout.AddView(dataGrid); SetContentView(layout); } private void RowScrollButton_Click(object sender, EventArgs e) { dataGrid.ScrollToRowIndex(3); } }
Screenshot
Scroll to column index
You can scroll programmatically to a particular column index using SfDataGrid.ScrollToColumnIndex method by passing column index as parameter.
private void ColumnScrollButton_Click(object sender, EventArgs e) { dataGrid.ScrollToColumnIndex(2); }
Screenshot
Scroll to row and column index
You can scroll programmatically to a particular row and column index using SfDataGrid.ScrollToRowColumnIndex method by passing row and column index as parameters.
private void RowColumnScrollButton_Click(object sender, EventArgs e) { dataGrid.ScrollToRowColumnIndex(6, 2); }
Screenshot
Sample: Scroll specific row/column