Xceed Grid for WinForms v4.3 Documentation
Welcome to Xceed Grid for WinForms v4.3 / Task-Based Help / Scrolling / How to synchronize the scrolling of two grids

In This Topic
    How to synchronize the scrolling of two grids
    In This Topic

    You can synchronize the scrolling of two grid's using the FirstVisibleRowChanged and FirstVisibleColumnChanged events.

    Demonstration

    The following example demonstrates how to scroll the second grid ( gridControl2 ) in sync with the first grid (gridControl1). If you want to sync the scrolling of the first grid when the second grid is scrolled, then you will also need to handle the FirstVisibleRowChanged and FirstVisibleColumnChanged events of the second grid.

    VB.NET Copy Code

    AddHandler GridControl1.FirstVisibleRowChanged, AddressOf Me.GridControl1_FirstVisibleRowChanged

    AddHandler GridControl1.FirstVisibleColumnChanged, _
                                  AddressOf Me.GridControl1_FirstVisibleColumnChanged 

    Private Sub GridControl1_FirstVisibleRowChanged(ByVal sender As Object, ByVal e As System.EventArgs)
      GridControl2.FirstVisibleRow = gridControl2.DataRows( CType( GridControl1.FirstVisibleRow, _
                                                            Xceed.Grid.DataRow ).Index)
    End Sub 

    Private Sub GridControl1_FirstVisibleColumnChanged(ByVal sender As Object, _
                                                       ByVal e As System.EventArgs)

      If Not GridControl1.FirstVisibleColumn Is Nothing And _
         Not GridControl2.FirstVisibleColumn Is Nothing Then

        GridControl2.FirstVisibleColumn = GridControl2.Columns( GridControl1.FirstVisibleColumn.Index )
      End If
    End Sub

    C# Copy Code

    gridControl1.FirstVisibleRowChanged += new EventHandler( this.gridControl1_FirstVisibleRowChanged );

    gridControl1.FirstVisibleColumnChanged +=
                     new EventHandler( this.gridControl1_FirstVisibleColumnChanged ); 

    private void gridControl1_FirstVisibleRowChanged(object sender, System.EventArgs e)
    {
      gridControl2.FirstVisibleRow = 
                gridControl2.DataRows[ ( ( Xceed.Grid.DataRow )ridControl1.FirstVisibleRow ).Index ];

    private void gridControl1_FirstVisibleColumnChanged(object sender, System.EventArgs e)
    {
      if( gridControl1.FirstVisibleColumn != null && gridControl2.FirstVisibleColumn != null )
        gridControl2.FirstVisibleColumn =
                gridControl2.Columns[ gridControl1.FirstVisibleColumn.Index ];                

    }