Datagridview: Copy row to array

S

Silvester

My datagridview has columns with text AND integers.

Please can someone help me with the code necessary to copy an entire
selected row of mixed content cells to an array ?

Thanks very much
 
J

John J. Hughes II

Silvester,

System.Collections.ArrayList array = new System.Collections.ArrayList();
for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
array.Add(this.dataGridView1[i, 0].Value); /// Make sure the second
value is a valid row

Regards,
John
 
G

Guest

Each DataGridViewRow has a DataBoundItem object property that represents the
underlying datasource for that row. So for example, if it was a DataRow from
a DataTable, that DataRow would sport a convenient ItemArray property.
Peter
 
S

Silvester

John / Peter,

Thank you for your replies. Will this code below pick up cell values for the
selected row ? System.Collections.ArrayList array = new
System.Collections.ArrayList();
for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
array.Add(this.dataGridView1[i, 0].Value); /// Make sure the second
value is a valid row

My source DGV is indeed databound.
Peter, please can you show me a code sample for your method ?
 

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