int i= dataGridView1.CurrentRow.Index;
DataGridViewRow dr = new DataGridViewRow();
foreach (DataGridViewColumn c in dataGridView1.Columns)
{
dr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
}
//假设有3列
dr.Cells[0].Value = textBox1.Text;
dr.Cells[1].Value = textBox2.Text;
dr.Cells[2].Value = textBox3.Text;
dataGridView1.Rows.Insert(i, dr);
本文介绍如何在C#中使用DataGridView控件添加新行,包括遍历列获取模板并复制,设置新行的值,然后插入到指定位置。
1万+

被折叠的 条评论
为什么被折叠?



