您的位置:首页 > 数据库

C# 在dataGridView中行首或行尾手动添加记录、修改一行记录(1.行尾添加,非数据库连接形式 2.修改某一行的数据 3.插入行首,不覆盖行首)

2016-12-07 13:43 3159 查看
1. 在行尾添加新的一行数据
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dataGridView1);
row.Cells[0].Value = 23;
row.Cells[1].Value = 45;
this.dataGridView1.Rows.Add(row);


2. 修改某一行的数据

int iRowIndex = n;
this.dataGridView1["Column1", iRowIndex].Value = "1";
this.dataGridView1["Column2", iRowIndex].Value = "张三";
this.dataGridView1["Column3", iRowIndex].Value = "软件部";


3. 在行首插入一天记录,不会覆盖原来数据,也可在任意位置插入

DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dataGridView1);
row.Cells[0].Value = "hh";
row.Cells[1].Value = "yy";
this.dataGridView1.Rows.Insert(0, row);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐