0

I need to get value from datagridview.

int selectedrowindex = dgvTable.SelectedCells[0].RowIndex;

DataGridViewRow selectedRow = dgvTable.Rows[selectedrowindex];

String id = selectedRow.Cells["F_id"].Value.ToString();

But I get the value of the next row (row_index + 1). Variable selectedrowindex is correct, but value of selectedRow is wrong.

alexander.skibin
  • 133
  • 1
  • 2
  • 15
  • Did you debug your code and check what your `dgvTable` has exactly as a rows? – Soner Gönül Jul 21 '15 at 08:17
  • Yes, I checked it and found out that `selectedrowindex` is correct, but `selectedRow` returns next value. – alexander.skibin Jul 21 '15 at 08:21
  • Please visit this link. http://stackoverflow.com/questions/11260843/getting-data-from-selected-datagridview-row-and-which-event http://stackoverflow.com/questions/13672693/how-do-i-select-a-complete-datagridview-row-when-the-user-clicks-a-cell-of-that http://stackoverflow.com/questions/3578144/index-of-currently-selected-row-in-datagridview – Suman Banerjee Jul 21 '15 at 08:26

1 Answers1

0

Use datagridviewrow and assigned as a variable.

datagridviewrow therowname = datagridviewname.rows[e.rowIndex];

After that, use this:

theobjectnamewantoassigned = therowname.cell[cellcolumnplaced].value;
Dharman
  • 30,962
  • 25
  • 85
  • 135