Scroll-synchronizing two or more DataGridViews

Hi,

I'm trying to synchonize scrolling of two grids, ContractProdGrid and ContractSuppliergrid,
by using the RowEnter event on one grid to control the other like this: 

    Private Sub ContractProdgrid_RowEnter(ByVal sender As Object, _
        ByVal e As DataGridViewCellEventArgs) Handles ContractProdGrid.RowEnter
        ContractSupplierGrid.CurrentCell = _ 
        ContractSupplierGrid.Rows(ContractProdGrid.CurrentCell.RowIndex).Cells(1)
    End Sub

But, when I start the application I get an NullReferenceException in this code,
what am I doing wrong

/cmkivio


Answer this question

Scroll-synchronizing two or more DataGridViews

  • Chris G.

    I can't find any cases where a RowEnter is fired but the row/grid is empty. Can you provide more details  Do check to see that the cell you are accessing is there (don't forget that the cell collection is 0 based.)

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

  • AndreaC

    It seems that the RowEnter event is triggered even if the grid is empty. How can one test for an empty grid or not initialized or is this a bug

    /cmkivio

  • Hassano21436

    Thanks for the suggestion but I am actually attempting to also row-sync so I suppose the RewEnter or CellEnter event is the one to use

    Anyway, I am using an unbound grid that is populated dynamically. Anyway, it seems that I made some things in wrong order so now the event is triggered as intended.

    Thanks!

  • Mike Rousos

    If you are only attempting to sync the scrolling you can also just use the Scroll event and set the FirstDisplayedScrollingRow/Column index.

    -mark 
    Program Manager 
    Microsoft 
    This post is provided "as-is"

  • Scroll-synchronizing two or more DataGridViews