Private m_ScrollClicked As Boolean = False ' if the scroll wheel is down this is set to true
Private m_StartLocation As Point ' this is the cursor position relative to the form when the scroll wheel is clicked
Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Middle Then
m_ScrollClicked = True ' the scroll wheel has been clicked
m_StartLocation = Windows.Forms.Cursor.Position 'set the position of where the scroll wheel was clicked
Windows.Forms.Cursor.Current = Cursors.HSplit 'change the cursor
Timer1.Start() 'star the timer
End If
End Sub
Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseMove
If m_ScrollClicked = True Then 'the cursor kept changing back to the default
Windows.Forms.Cursor.Current = Cursors.HSplit 'so reset it to your cursor when the mouse moves and the scroll is down
End If
End Sub
Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp
m_ScrollClicked = False 'when a mouse button goes up, I assume it is the middle
Windows.Forms.Cursor.Current = Cursors.Default 'change the cusor back to default
Timer1.Stop() 'stop the timer
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'The timer is what actually moves the listview. If the current y is less than the clicked you move up
'if the current y is greater than the clicked y you move down
Dim i As Integer = ListView1.Items.IndexOf(ListView1.TopItem) 'gets the index of the first item that can be seen
If m_ScrollClicked = True AndAlso Windows.Forms.Cursor.Position.Y < m_StartLocation.Y Then
If i > 0 Then 'if there is an item above it, change the top item to that
ListView1.TopItem = ListView1.Items.Item(i - 1)
End If
ElseIf m_ScrollClicked = True AndAlso Windows.Forms.Cursor.Position.Y > m_StartLocation.Y Then
If i < ListView1.Items.Count - 1 Then 'if there is an item below it, change the item to that
ListView1.TopItem = ListView1.Items.Item(i + 1)
End If
End If
End Sub