DataGridView.Rows.Insert或DataGridView.Rows.InsertCopy方法不起作用

时间:2019-03-23 13:13:12

标签: c# winforms datagridview

无法通过使用DataGridView.Rows.Insert或DataGridView.Rows.InsertCopy方法在DataGridView中的特定位置插入新行。

错误消息:当控件与数据绑定时,不能以编程方式将行添加到DataGridView的行集合中。

DataGridViewRow dgwr = new DataGridViewRow();
dgwr.CreateCells(myDataGridView);
myDataGridView.AllowUserToAddRows = true;
myDataGridView.AllowUserToDeleteRows = true;
myDataGridView.Rows.Insert(5, dgwr);

OR

myDataGridView.AllowUserToAddRows = true;
myDataGridView.AllowUserToDeleteRows = true;
myDataGridView.Rows.InsertCopy(5, 2);

enter image description here

0 个答案:

没有答案
相关问题