I'm having a real headache getting the selected row from my datagrid (only one row can be selected at a time).

If I use the callback function from clicking on the data grid I can get the selected row no problem

dgStaffList_CellContentClick(object sender, DataGridViewCellEventArgs e)
int selectedRow = e.RowIndex;

However I want other methods to be able to read the cell contents without any user interaction.

Any idea how to do this?

try this:

int rowSelected = dataGridView1.CurrentCell.RowIndex;

You can also reference the cells by their column names, like this:

string myValue = dgStaffList.SelectedRows[0].Cells["FirstName"].Value.ToString();

SelectedRows[] is 0 because you only have one row selected. You can also reference the cell by column position instead of name, just substitute a 0-indexed integer for the column number in the place of "FirstName".

can use this line of code also


int rowSelected = dataGridView1.CurrentCell.RowIndex;

worked a dream

:) I thought it has to work.
And close the thread (mark as answered).