Get the index of the SelectedRow in a DataGridView

The below codes show how to do that

private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{

if (dataGridView1.SelectedRows.Count == 1)
{
txtCustcode.Text = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells["CustomerCode"].Value.ToString();
}
}

0 comments :

Post a Comment