vs2005 - Getting the ID from the selected row in a DGV

  • Thread starter Thread starter dbuchanan
  • Start date Start date
D

dbuchanan

Hello,

How do I get the ID, or any column value from the selected row in a
dataGridView?

I am using a tableAdapter and of course a bindingSource to populate the
dataGridView.

In my case some of the columns are turned off in the dataGridView. Can
I still access the value?


Thank you,
dbuchanan
 
If they are turned off (visible = false) then you can still access
them.
(typecast)dgv.SelectedRows[0].Cells["CellName"].Value
should give you it.

So say your DataGridView is "dgv", your Column you want data from is
"ID" and it's an Int32 value:

Int32 colid = (Int32) dgv.SelectedRows[0].Cells["ID"].Value;

Good luck
 
Back
Top