Hello:
I would llike to get the data from a row in a dataGrid by the name of the column. How do I do that?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
NainilPosted Mar 12, 2010, 2:58 PM
Let's say you want to get the 2nd Column value from a DataGridViewRow object. To do this, first you obtain a reference to the DataGridViewRow obect and query the Cells property (which returns DataGridViewCellCollection) by index. You can either use an integer index (1 if you want the 2nd Column) or string for the column. Following could be the sample code:
string company = dataGridView1.Rows[0].Cells["Company"].Value.ToString(); // Uses string as an indexer
string company = dataGridView1.Rows[0].Cells[1].Value.ToString(); // Uses integer as an indexer
I have attached a sample for your reference. Hope it helps.
GustavoPosted Mar 12, 2010, 3:01 PM
Thanks... it worked.