prevent的ListView从取消

prevent的ListView从取消

本文介绍了prevent的ListView从取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有在ListView 1个或多个项目,用户点击ListView中的空白,所选择的项目应保持选定。

If there is 1 or more items in the listview and the user clicks in the whitespace of the ListView, the item selected should stay selected.

在换句话说,如果选择了一个项目,应该保持选定除非选择另一个项目

In other words, if an item is selected it should stay selected unless another item is chosen.

我在ListView HideSelection 的设置为false,这将使所选的ListViewItem留选中时控件失去焦点的财产。但是,这并没有解决这个问题,当我在ListView的空白点击。

I have the property of the ListView HideSelection set to false which will make the selected ListViewItem stay selected when the control loses focus. However, this does not solve the issue when I click in the whitespace of the Listview.

有什么建议?

推荐答案

您可以通过继承实现这一目标的的ListView

You can achieve this by subclassing the ListView:

Public Class UIListView
    Inherits ListView

    Private Sub WmLButtonDown(ByRef m As Message)
        Dim pt As Point = New Point(m.LParam.ToInt32())
        Dim ht As ListViewHitTestInfo = Me.HitTest(pt)
        If (ht.Item Is Nothing) Then
            m.Result = IntPtr.Zero
        Else
            MyBase.WndProc(m)
        End If
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Select Case m.Msg
            Case WM_LBUTTONDOWN
                Me.WmLButtonDown(m)
                Exit Select
            Case Else
                MyBase.WndProc(m)
                Exit Select
        End Select
    End Sub

    Private Const WM_LBUTTONDOWN As Integer = &H201

End Class

这篇关于prevent的ListView从取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:21