如何在VB.net中突出显示MouseHover事件上的Listview项?

时间:2012-10-02 15:22:52

标签: vb.net listview

如何突出显示VB.net中Listview事件的MouseHover项, 就像Windows资源管理器一样?

2 个答案:

答案 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