Synchronize Scroll Events of two DataGridView Control
Some time there is a need to synchronize scroll event of two or more DataGridView controls, then you can write code like below on first DataGridView Scroll event.
Private Sub DataGridView1_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles DataGridView1.Scroll
If e.ScrollOrientation = ScrollOrientation.VerticalScroll Then Exit Sub
If Me.DataGridView2.Rows.Count > 0 And Me.DataGridView1.Rows.Count > 0 Then
Me.DataGridView2.HorizontalScrollingOffset = e.NewValue 'Me.DataGridView1.HorizontalScrollingOffset
End If
End Sub
and write code displayed below on second DataGridView Scroll event
Private Sub DataGridView2_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles DataGridView2.Scroll
If e.ScrollOrientation = ScrollOrientation.VerticalScroll Then Exit Sub
If Me.DataGridView1.Rows.Count > 0 And Me.DataGridView2.Rows.Count > 0 Then
Me.DataGridView1.HorizontalScrollingOffset = e.NewValue 'Me.DataGridView2.HorizontalScrollingOffset
End If
End Sub
This code will help to synchronize scroll event of both DataGridView controls. After writing this code you will see that if you are scrolling only one DGV, another DGV will automatically scroll.
Thank you for your help. (:
ReplyDeleteThanks and that i have a dandy proposal: Whole House Remodel Cost home remodeling companies
ReplyDelete