0

Hi,I has a problem here...

I has a datagridview and now I would like to determine that whether column1 in row 1 is selected by the user.What should I write to do so?

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        If (DataGridView1.Rows(1).Cells(1).Selected) Then
            MessageBox.Show("")
        End If
    End Sub
2
Contributors
1
Reply
14
Views
8 Years
Discussion Span
Last Post by Teme64
0

In the DataGridView control indices start from 0, so I've used 0 instead of 1.

You can trap CellClick event handler

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  '
  If e.ColumnIndex = 0 AndAlso e.RowIndex = 0 Then
    ' User clicked Col0 and Row0
  End If

End Sub

If you want to check selected cell outside any event

Dim oCell As DataGridViewCell
  For Each oCell In DataGridView1.SelectedCells
    If oCell.ColumnIndex = 0 AndAlso oCell.RowIndex = 0 Then
      ' User has selected Col0 and Row0
    End If
  Next

HTH

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.