Question Listview Item Selected

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
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?

VB.NET:
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
 
Set the ListViewItem.Focused property to True also.
 
Thanks that worked. Also can the actual mouse scrolling be stopped? Like when i scroll my mouse on the listview, the scroll bar doesnt move, and only the next item is selected by the code.
 
You can set ListView.Scrollable to False.
 
If i do that, the ensurevisible wont work, and i cant see anything below what is already displayed. I just want the mousewheel not to scroll it and manually scrolling it with code.
 
Back
Top