请问 BindingSource怎么用呢?
遇到的问题是:用窗体的load事件将txt绑定给了dataGridView,通过传值手动为dataGridView添加行,这两个冲突。
dataGridView1.Rows.Add(diandan);
(错误:当控件被数据绑定时,无法以编程方式向 DataGridView 的行集合中添加行。)
网上查了一下,说可以用BindingSource中转一下。
遇到的问题是:用窗体的load事件将txt绑定给了dataGridView,通过传值手动为dataGridView添加行,这两个冲突。
dataGridView1.Rows.Add(diandan);
(错误:当控件被数据绑定时,无法以编程方式向 DataGridView 的行集合中添加行。)
网上查了一下,说可以用BindingSource中转一下。
改用
DataTable table=dataGridView1.DataSource as DataTable;
table.Rows.Add(diandan);
dataGridView1.DataSource=table;
1、原数据源即txt不能为空;2、因为我用的是窗体传值,通过txt保留信息,在窗体关闭在打开时修改的数据依然存在(此过程没有退出调试),所以在每次修改时都会多一行空行。