如何突出显示VB.net中Listview
事件的MouseHover
项,
就像Windows资源管理器一样?
答案 0 :(得分:2)
将HoverSelection
控件的ListView
属性设置为True
。但是,如果要立即选择它,可以手动实现。例如,您可以尝试这样的事情:
Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseMove
Dim currentItem As ListViewItem = ListView1.GetItemAt(e.X, e.Y)
For Each item As ListViewItem In ListView1.Items
item.Selected = False
Next
If currentItem IsNot Nothing Then
currentItem.Selected = True
End If
End Sub
请确保HideSelection
控件上的ListView
属性设置为False
,否则除非列表具有焦点,否则不会显示选择。
答案 1 :(得分:0)
不闪烁:
Private Sub ListView1_MouseMove(sender As Object, e As MouseEventArgs) Handles ListView1.MouseMove
Dim currentItem As ListViewItem = ListView1.GetItemAt(e.X, e.Y)
For Each item As ListViewItem In ListView1.Items
If currentItem IsNot Nothing Then
currentItem.Selected = True
Else
item.Selected = False
End If
Next
End Sub