I have a DataGridView table with two columns (id
and Description
). When the user selects a cell which is in the description column, I want to be able to get the id
value which is next to the cell on the left.
Here is what I have so far:
dataGridView1.CellClick += (s, e) =>
{
int id;
DataGridViewCell cell = dataGridView1.SelectedCells[0];
//Instead of this, what do I put to get the ID column?
if (cell.ColumnIndex == 0)
id = Convert.ToInt32(cell.Value);
else
return;
string[] data = UnitData[id];
txtNum.Text = id.ToString();
txtName.Text = data[0];
txtDesc.Text = data[1];
};
I want to be able to check if the column selected is description, if it is, get the cell next to it.
How would I accomplish this?