首页 > 解决方案 > DataGridView.Rows.Insert 或 DataGridView.Rows.InsertCopy 方法不起作用

问题描述

无法使用 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);

或者

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

在此处输入图像描述

标签: c#winformsdatagridview

解决方案


推荐阅读