Scrolling Mouse wheel in empty Datagridview Resulting Error Vb.bet

Viewed 35

Whenever I am in the last row and keep scrolling down with the mouse wheel in datagridview always resulting an error.

It didn't result in an exception but entered break mode in my visual studio.

For Ex. I have a datagridview with 10 rows. when i scroll to the 10th row it still ok. And then I playing with my mouse wheel, scrolling it down while i am in last position, and my program entered break mode.

I tried to put debug in my mouse wheel code, but it didn't get caught in Exception. It just bring me straight to break mode.

 Private Sub dgvKonfirmasi_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgvKonfirmasi.MouseWheel

    Try
        Dim currentIndex As Integer = Me.dgvKonfirmasi.FirstDisplayedScrollingRowIndex
        Dim scrollLines As Integer = SystemInformation.MouseWheelScrollLines

        If e.Delta > 0 Then
            If Me.dgvKonfirmasi.Rows.Count > (currentIndex + scrollLines) Then Me.dgvKonfirmasi.FirstDisplayedScrollingRowIndex = Math.Max(0, currentIndex - scrollLines)
        ElseIf e.Delta < 0 Then
            If Me.dgvKonfirmasi.Rows.Count > (currentIndex + scrollLines) Then Me.dgvKonfirmasi.FirstDisplayedScrollingRowIndex = currentIndex + scrollLines
        End If
    Catch ex As Exception

    End Try

End Sub

enter image description here

0 Answers
Related