-1

但找不到任何信息。时间有限。

我有一个 Datagridview,6 个字段。

我需要制作一个仅包含其中 2 个字段的数据表。

字段是部分和帕累托。

所以我需要所有记录,但只需要我的数据表中的 2 个字段。

使用 c sharp .net 4.0 和 Microsoft Visual Studio 2010

4

2 回答 2

2
DataGridViewRowCollection coll = dataGridView1.Rows; 

DataTable t = new DataTable(); 

t.Columns.Add(); 

foreach (DataGridViewRow item in coll) 

{
     t.Rows.Add(item.Cells[0].Value);
}

只需从每一行添加您想要的单元格。您需要做的就是过滤列。

于 2012-04-04T11:05:25.867 回答
2
foreach( DataGridViewRow row in myDataGridView.Rows)
{
      DataRow tableRow = myDataTable.NewRow();
      tableRow.Cells["part"].value = row["part"].value;
      tableRow.Cells["pareto"].value = row["pareto"].value;
      myDataTable.Rows.Add(tableRow);
}

像这样的事情应该这样做。只需确保您的 DataTable 具有适当的行。

于 2012-04-04T11:07:33.210 回答