Articles in this section
Category / Section

How to scroll to a specific row/column programmatically in SfDataGrid?

1 min read

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

C:\Users\indhumathy.malayappa\AppData\Local\Microsoft\Windows\INetCacheContent.Word\Capture3.png

 

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

C:\Users\indhumathy.malayappa\AppData\Local\Microsoft\Windows\INetCacheContent.Word\Capture5.png

 

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

C:\Users\indhumathy.malayappa\AppData\Local\Microsoft\Windows\INetCacheContent.Word\Capture7.png

 

Sample: Scroll specific row/column

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