Programmatically scroll a DataGrid to a given row

The DataGrid has a protected GridVScrolled method that can be used to scroll the grid to a specific row. To use it, derive a new grid from the DataGrid and add a ScrollToRow method.

C# code

    public void ScrollToRow(int theRow)
    {
        //
        // Expose the protected GridVScrolled method allowing you
        // to programmatically scroll the grid to a particular row.
        //
        if (DataSource != null)
        {
            GridVScrolled(this, new ScrollEventArgs(ScrollEventType.LargeIncrement, theRow));
        }
    }

VB.NET code

    Public Sub ScrollToRow(ByVal theRow As Integer)
        '
        ' Expose the protected GridVScrolled method allowing you
        ' to programmatically scroll the grid to a particular row.
        '
        On Error Resume Next

        If Not DataSource Is Nothing Then
            GridVScrolled(Me, New ScrollEventArgs(ScrollEventType.LargeIncrement, theRow))
        End If
    End Sub







About TheScarms
About TheScarms


Sample code
version info

If you use this code, please mention "www.TheScarms.com"

Email this page



The World's Number 1 Web Host

© Copyright 2014 TheScarms
Goto top of page