[英]Remove row from a DataGridView
我有一个带有7个单元格的DataGridView,如果我按Public Event EscapeOnFirstRowPressed
键,我会进入的每个单元格都将删除当前行,这是我创建的名为Public Event EscapeOnFirstRowPressed
,没有任何问题,并将控件带到了每个初始状态。
这个过程的总体思路是当所有单元都满足时
由于“写”过程正常,因此我将兴趣移出该行。
我说这个动作需要从RowValidated
子程序或从CellEnter
(当我离开当前行并到达下一行时发生)调用它。 但是在任何地方,如果我输入命令
If Not DGV.CurrentCell.EditedFormattedValue = "" Then
If Not DGV.Rows(RowIndex).IsNewRow Then
DGV.Rows.RemoveAt(RowIndex)
DGV.Refresh()
End If
ElseIf DGV.CurrentCell.EditedFormattedValue = Nothing Then
If Not DGV.Rows(RowIndex).IsNewRow Then
DGV.Rows.RemoveAt(RowIndex)
DGV.Refresh()
End If
End If
我收到以下错误
DGV.Rows.RemoveAt(0) {"Operation cannot be performed in this event handler."}
我正在尝试另一种方法来执行此操作。 我尝试通过给出以下命令来模拟KeyPress动作
Dim myKeyData As System.Windows.Forms.Keys
Dim myMsg As System.Windows.Forms.Message
myKeyData = Keys.Escape
ProcessCmdKey(myMsg, myKeyData)
但是,当指针执行与按Esc键时执行的指令相同的指令时,我会收到相同的错误。
您可以在事件处理程序完成之后,通过调用BeginInvoke
在下一个消息循环中执行代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.