一、 DATAGRIDVIEW 数值传递给datable

 

int cn = dataGridView1.Rows.Count;
int col = dataGridView1.ColumnCount;
for (int j = 0; j < col;j++ )
{
DataColumn dc = new DataColumn(dataGridView1.Columns[j].Name.ToString());
dt.Columns.Add(dc);
}
for (int m = 0;m< cn; m++)
{
DataRow dr = dt.NewRow();
for (int n = 0; n < col;n++ )
{
dr[n] = Convert.ToString(dataGridView1.Rows[m].Cells[n].Value);
}

dt.Rows.Add(dr);

}

 

二、datatable 数值 传递到datagridview

 DataTable dt = new DataTable();

for (int x = 0; x < dt.Rows.Count; x++)
{

bool yn = Convert.ToBoolean(Convert.ToInt32(dt.Rows[x][0].ToString()));
dataGridView1.Rows.Add(yn, (x + 1).ToString(), (dt.Rows[x][2].ToString()), (dt.Rows[x][3].ToString()), (dt.Rows[x][4].ToString()));
}

posted on 2019-12-29 14:55  Lionever  阅读(4473)  评论(0编辑  收藏  举报