Datagridview: Copy row to array

  • Thread starter Thread starter Silvester
  • Start date Start date
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
 
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
 
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
 
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 ?
 
Back
Top