Disable Cell Highlighting in a datagridview

前端 未结 10 1931
后悔当初
后悔当初 2020-12-08 13:30

How to disable Cell Highlighting in a datagridview, Highlighting should not happen even if I click on the cell.

Any thoughts please

10条回答
  •  星月不相逢
    2020-12-08 14:01

    Private Sub DataGridView1_SelectionChanged(sender As Object, e As System.EventArgs) Handles DataGridView1.SelectionChanged
        Me.DataGridView1.ClearSelection()
    End Sub
    

    That's it. But if you still want to get clicked row/cell index or to access values:

    Private Sub DataGridView1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
        Dim _ht As DataGridView.HitTestInfo = Me.DataGridView1.HitTest(e.X, e.Y)
        If _ht.Type = DataGridViewHitTestType.Cell Then
            Me.DataGridView1.Rows(_ht.RowIndex).Cells(_ht.ColumnIndex).Value = _
            "RowIndex = " & _ht.RowIndex & ", " & "ColumnIndex = " & _ht.ColumnIndex
        End If
    End Sub
    

提交回复
热议问题