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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.