0

I have code on vb.net which is checking radiobutton3 whenever a cell has clicked. But it also works when columnheader or rowheader clicked. How i can make this code inaccesable for columheader and rowheader click?

Private Sub MyDataGridView1_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles MyDataGridView1.CellMouseClick
        RadioButton3.Checked = True

    End Sub
Macukadam
  • 45
  • 2
  • 12

2 Answers2

0
Private Sub MyDataGridView1_MouseDown(sender As Object, e As MouseEventArgs) Handles MyDataGridView1.MouseDown
    Dim ht As DataGridView.HitTestInfo
    ht = Me.MyDataGridView1.HitTest(e.X, e.Y)
    If ht.Type = DataGridViewHitTestType.Cell Then
        RadioButton3.Checked = True
        cont()
    End If
End Sub

This link helped: context menu for datagridview cell, rowheader and columnheader

Community
  • 1
  • 1
Macukadam
  • 45
  • 2
  • 12
0

e.RowIndex=-1 represents the row header. e.ColumnIndex=-1 represents the column header.

You can check as following:

Private Sub shipmentDetailsDataGridView_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs)

    RadioButton3.Checked = e.ColumnIndex >= 0 AndAlso e.RowIndex >= 0

End Sub
ehh
  • 3,412
  • 7
  • 43
  • 91