Winforms ListView - Stop automatically checking when double clicking

后端 未结 5 1458
粉色の甜心
粉色の甜心 2021-02-19 04:15

How do I make a listview not automatically check an item when I double click it?

I can try hooking into the MouseDoubleClick event, and set the Checked property to false

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-19 04:50

    I had a similar problem, and this is how I handled it. Basically if the item is checked while the cursor's x coordinate is greater than the checkbox's x coordinate, then I cancel the check (because it means the check was called when the user double clicked the item).

    The margin of error with the number 22 is only if the user double clicks right after the check box (very hard to do).

    NOTE: My code assumes the user will not double click the checkbox (either the user double clicks the item or single clicks the checkbox)

    Sorry code is in VB :)

    Private Sub lvComboLists_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles lvComboLists.ItemCheck
        Dim i As Integer = CType(sender, ListView).PointToClient(Cursor.Position).X
        If i > 22 Then
            e.NewValue = e.CurrentValue
        End If
    End Sub
    

提交回复
热议问题