How to deselect all selected rows in a DataGridView control?

前端 未结 6 645
臣服心动
臣服心动 2021-01-31 01:24

I\'d like to deselect all selected rows in a DataGridView control when the user clicks on a blank (non-row) part of the control.
How can I do this?

6条回答
  •  北荒
    北荒 (楼主)
    2021-01-31 02:29

    In VB.net use for the Sub:

        Private Sub dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgv.MouseUp
        ' deselezionare se click su vuoto
        If e.Button = MouseButtons.Left Then
            ' Check the HitTest information for this click location
            If Equals(dgv.HitTest(e.X, e.Y), DataGridView.HitTestInfo.Nowhere) Then
                dgv.ClearSelection()
                dgv.CurrentCell = Nothing
            End If
        End If
    End Sub
    

提交回复
热议问题