[英]How to commit edit or end edit on selection confirmed for datagridview combobox cell?
問題:當用戶有一個 datagridview 組合框單元格時,我想提交一個編輯,即它將是常規組合框單元格的“已提交選擇”
我已經嘗試過:因此基於很多堆棧流問題(例如Datagridview comboBox not selection on click/edit ),他們查看調用的事件,例如選定索引更改、單元格值更改、單元格內容單擊和編輯控件顯示。 在這些事件處理程序中,我嘗試提交編輯,但它會在單擊另一個單元格后調用此事件,而不是在單元格中選擇所選項目后調用此事件。 我已經嘗試過制作“選定的索引已更改”處理程序和定義,但由於組合框單元格沒有該事件,我在 vb.net 中收到錯誤
這是一個示例代碼片段:
Private Sub editingComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
editCameraTable.CommitEdit(DataGridViewDataErrorContexts.Commit)
editCameraTable.EndEdit()
End Sub
在單擊另一個單元格或以其他方式之前,不會調用此方法。 有關如何為 datagridviewcomboboxcell 標記此事件的任何建議?
處理 CellEndEdit 動作。 是的,它只會在用戶點擊其他地方后觸發; 但將它與按鍵預覽結合起來。人們自然會在文本編輯結束時單擊返回,您可以使用它來觸發更新。 網格視圖中的單元格無法確定一個人何時完成輸入,因此它需要該人在編輯提交發生之前單擊它。 解決此問題的唯一其他方法可能是使用計時器,該計時器在每個按鍵事件上重置並在打字空閑時更新。
Private Sub datagridview1_CellEndEdit(ByVal sender As Object, _
ByVal e As System.EventArgs) HAndels datagridview1.CellEndEdit
' If InLoad = True Then Exit Sub ' may want to suppress if you are programmatically changing this
datagridview1.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange)
' Do your saves...
End Sub
Private Sub datagridview1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) _
Handles datagridview1.KeyDown
If e.KeyCode = Keys.Return Then
datagridview1.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange)
End If
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.