已绑定的DataGridview添加新记录 我的目的:一个DataGridView中显示了用户的基本信息,我用弹出窗口添加一条记录信息,当添加到数据库成功后,要在DataGridView中显示出刚才添加的那条记录,但不想重新读取数据,重新绑定DataGridView。只是把那条记录加到DataGridView中即可本人是新手,希望各位可以将具体点。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 winform传值forach(DataRow dr in dt.Rows){DataGridViewRow row = new DataGridViewRow(); row.Cells[0].Value =dt[""].ToString(); row.Cells[1].Value = dt[""].ToString(); this.dataGridView1.Rows.Add(row);}或DataGridViewRow dr = dataGridView1.Rows[dataGridView1.NewRowIndex]; dataGridView1.Rows.Add(dr); http://topic.csdn.net/u/20090520/11/c603b363-38bd-4b9b-8634-09cde2994682.html DataTable dt1 = new DataTable();//新建一個datatable用於保存讀入的資料 DataRow dr = dt1.NewRow();//新建一行dr[0] = "1234"; dr[1] = "5678";dt1.Rows.Add(dr);//將這行數據加入到datatable中 this.dataGridView1.DataSource = dt1;//重新綁訂資料 弹出窗口再增加到数据库的同时,按钮也将新记录写到datagridview。 作为DataGridView的数据源如果是DataTable,直接在DataTable中添加记录就能够反映到DataGridView中。 WPF窗口比例如何保持恒定? 一个关于Windows 系统服务的问题 Buffer.BlockCopy()的用法 急求PPS网络电视标题栏上除了一般的 关闭 最大化 最小化 之外的另一个按钮怎么得到 有人开发过smart client吗,是.net 1.1的,好像微软不提供自动更新组件下载了 用DataSet更新数据老出现并发冲突 请教webBrowser.Navigate()网页跳转问题 帮帮小妹!急死了!(在线等待) 哪里有高级的软件设计理论专题? 听说QQ要收费了,,,,能留下MSN吗? 关于DATATABLE合并 C#实现DICOM格式图像的打印功能
forach(DataRow dr in dt.Rows)
{
DataGridViewRow row = new DataGridViewRow();
row.Cells[0].Value =dt[""].ToString();
row.Cells[1].Value = dt[""].ToString();
this.dataGridView1.Rows.Add(row);
}
或
DataGridViewRow dr = dataGridView1.Rows[dataGridView1.NewRowIndex];
dataGridView1.Rows.Add(dr);
DataTable dt1 = new DataTable();//新建一個datatable用於保存讀入的資料
DataRow dr = dt1.NewRow();//新建一行
dr[0] = "1234";
dr[1] = "5678";
dt1.Rows.Add(dr);//將這行數據加入到datatable中
this.dataGridView1.DataSource = dt1;//重新綁訂資料