Here is the code snippet
String ID;
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if ((e.RowIndex == -1))
{
MessageBox.Show("");
}
else
{
try
{
ID = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
}
catch(Exception ex)
{
MessageBox.Show("Error:" + ex.Message.ToString());
}
}
}
Generate this cell click event and try this code; just update the cell value which cell value you want to pass.
Hope it helps.