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

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
 
E

Edan Starfire

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top