Search Amazon:

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
Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

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

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2009 TheScarms