怎么向C#中的datagriview逐条添加数据

如题所述

DataGridViewRow row = new DataGridViewRow(); //新建一个DataGridViewRow
foreach (DataGridViewColumn c in dataGridView1.Columns)
{
row.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);//给行添加单元格
}
row.Cells[0].Value = reader.GetString(0); //给DataGridViewRow添加数据
row.Cells[1].Value = reader.GetString(1); //给DataGridViewRow添加数据
row.Cells[2].Value = reader.GetString(2); //给DataGridViewRow添加数据
dataGridView1.Rows.Add(row); //添加进DataGridView
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-07-06
将数据放在DataTable中,然后再绑定本回答被网友采纳
相似回答