正如标题所暗示的,我有两个数据网格视图相互并排。我想让第一个数据网格视图没有滚动条但允许鼠标滚轮滚动。当我滚动第二个数据网格视图时,我已经设法同步2数据网格视图。下面是代码
Private Sub dgvA_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles dgvA.Scroll
dgvB.FirstDisplayedScrollingRowIndex = dgvA.FirstDisplayedScrollingRowIndex
dgvB.HorizontalScrollingOffset = dgvA.HorizontalScrollingOffset
End Sub
Private Sub dgvB_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles dgvB.Scroll
dgvA.FirstDisplayedScrollingRowIndex = dgvB.FirstDisplayedScrollingRowIndex
dgvA.HorizontalScrollingOffset = dgvB.HorizontalScrollingOffset
End Sub
答案 0 :(得分:1)
使用这些代码进行管理
Private Sub dgvA_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgvA.MouseWheel
Dim currentIndex As Integer = Me.dgvA.FirstDisplayedScrollingRowIndex
Dim scrollLines As Integer = SystemInformation.MouseWheelScrollLines
Select Case e.Delta
Case (120)
Me.dgvA.FirstDisplayedScrollingRowIndex = Math.Max(0, currentIndex - scrollLines)
Case (-120)
Me.dgvA.FirstDisplayedScrollingRowIndex = currentIndex + scrollLines
End Select
End Sub