以编程方式使新行变脏并在DataGridView中插入新行

Ism*_*ilS 6 c# datagridview winforms c#-3.0

我有一个可编辑的无界数据网格视图.我正在以编程方式更改新行的值.

通常,当用户键入新行的任何字段时,它会变脏并在其下方插入另一个新行.

但在我的情况下,当用户进入新行的任何字段时,我正在捕获功能键并以编程方式更改单元格值.

myGrid.CurrentCell.Value ="xyz";

并且它不会在它下面插入新行.

现在作为一个解决方法我在CellValueChanged事件处理程序上尝试了这个.

  if (myGrid.NewRowIndex == e.RowIndex)
  {
    myGrid.Rows.Insert(e.RowIndex + 1, 1);
  }
Run Code Online (Sandbox Code Playgroud)

但它引发了错误说法No row can be inserted after the uncommitted new row..

我怎么能告诉myGrid我的当前行(这是一个新行)是脏的,并且之后需要一个新行?

Hai*_*ihi 7

我正在使用winforms DataGridView.在我的情况下,我尝试了@iSid解决方案,但这里有一个帮助,我试过这个

myGrid.NotifyCurrentCellDirty(true);
myGrid.NotifyCurrentCellDirty(false);
Run Code Online (Sandbox Code Playgroud)

通过仅使当前单元格无法工作,您还必须提交该单元格.在下一个命令中,我标记当前单元格不脏,这将​​强制datagridview添加脏行.它正在我的项目中工作.


Ism*_*ilS 6

我在这里得到了解决方案

myGrid.NotifyCurrentCellDirty(true);
Run Code Online (Sandbox Code Playgroud)