Hi

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?

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".

This question has already been answered. Start a new discussion instead.