[英]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.