Please put a break point inside the
manageSelection
method and run the program. When execution stops at the break point, check whether
selection
value is less than
Rows.Count
and check whether all the indices given for
Cells
are valid i.e. less than the
Rows[selection].Cells.Count.
Since,
out of index
error is throw either the
Row index
is more than the number of rows or the
Cell index
may be more the number of cells.
[Edit]Code to illustrate usage of
CurrentRow
method of
DataGridView
[/Edit]
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
DataGridViewRow currentRow = dataGridView1.CurrentRow;
if (currentRow != null)
manageSelection(currentRow);
}
Define manageSelection method as
void manageSelection(DataGridViewRow row){
nameBox.Text = row.Cells[1].Value.ToString();
}