开发者

how can you programatically tell if a group header is clicked in a .NET ListView?

What we're looking to do is determine if a group header has been clicked, like the "Hard Disk Drives" or the "Devices with Removable Storage" headers in the My Computer on Vista/7 screen. This has to work in XP.

We can detect when a mouse is in the region, and 开发者_Go百科then trap a click, but we'd like to know if there is a specific event.


There is an article that implements a custom ListView control which I believe the author has tackled the problem of clicking on a group here. There is another article which shows which header is clicked on although I am not 100% confident if that is in the context of a group header...but I would imagine it would be the same principle for group headers...

Hope this helps, Best regards, Tom.


Here is what I use, hope it will be of help:

   Private Sub ListView1_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles ListView1.PreviewMouseDown

    If e.LeftButton = MouseButtonState.Pressed Then

        Dim pt As Point = e.GetPosition(Me)
        Dim ListViewComponent As Object = System.Windows.Media.VisualTreeHelper.HitTest(Me, pt)
        If ListViewComponent.visualhit.ToString = "System.Windows.Controls.Border" Then
            ' mouse down event was on header row  
        Else
            ' mouse down event was not on the header row  
        End If
        ListViewComponent = Nothing
        pt = Nothing

    End If

End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜