- Nov 28, 2008
- Programming Experience
I tried to use the mousewheel to select the next and previous item in a listview. It all works fine until i hit the up and down arrow on the keyboard, it will go back to the beginning and scroll to the next item from the beginning. When i use the mousewheel, it seems to leave a dotted line around the item that it begin with from using the keyboard or clicking. How do i move that with the wheel as well so when i hit the arrow, it doesnt jump back up to a different spot?
Private Sub listview1_MouseWheel(sender As Object, e As MouseEventArgs) Handles listview1.MouseWheel Dim index As Integer = listview1.SelectedItems(0).Index If e.Delta > 0 Then 'scroll up If index > 0 Then listview1.SelectedItems.Clear() listview1.Items(index - 1).Selected = True End If End If Else 'scroll down If index < listview1.Items.Count - 1 Then listview1.SelectedItems.Clear() listview1.Items(index + 1).Selected = True End If End If End Sub