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?
How do I: Get dataGrid values by the colum name?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Nainil148 reputationPosted Mar 12, 2010, 9:58 AM EST
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.
GustavoRank #1,990 · 732 reputationPosted Mar 12, 2010, 10:01 AM EST
Thanks... it worked.