I am trying to get the cell values of the row that I clicked.
here's my code..
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
txtFullName.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
txtUsername.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
txtPassword.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
}
works fine.. but it doesn't work when I click on the row(left side of the UserID) and on user id column... it also gives me an error when I click on the column header. how can I fix that error and I want it to also click on row and userid column.

You are using the wrong event: Try this
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > -1)
{
var val = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With