我有DatagridComboBoxColumn數據網格,我想火災事件的SelectionChanged當用戶選擇任何東西從ComboBox,做一些操作, 我怎麼能做到這一點的任何建議, 感謝選擇改變事件在DataGridComboBoxColumn
1
A
回答
12
您可以處理DataGridView的EditingControlShowing
事件,並將編輯控件強制轉換爲正在顯示的組合框,然後連接其SelectionChangeCommitted
事件。使用SelectionChangeCommitted
處理程序,你需要做什麼。
請參閱MSDN文章我聯繫瞭解詳細信息中的示例代碼。
兩個重要注意事項:
儘管MSDN本文的示例代碼,最好使用 組合框
SelectionChangeCommitted
事件,所討論的here和鏈接的MSDN文章的 意見。如果你有一個以上的
DatagridComboBoxColumn
在 DataGridView中,你可能要確定哪些解僱或者您的EditingControlShowing
或組合框的SelectionChangeCommitted
事件。您可以通過檢查您的DGVCurrentCell.ColumnIndex
屬性值來執行此操作。
我修改了MSDN示例代碼位,以顯示我的意思:
Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
' Only for a DatagridComboBoxColumn at ColumnIndex 1.
If DataGridView1.CurrentCell.ColumnIndex = 1 Then
Dim combo As ComboBox = CType(e.Control, ComboBox)
If (combo IsNot Nothing) Then
' Remove an existing event-handler, if present, to avoid
' adding multiple handlers when the editing control is reused.
RemoveHandler combo.SelectionChangeCommitted, New EventHandler(AddressOf ComboBox_SelectionChangeCommitted)
' Add the event handler.
AddHandler combo.SelectionChangeCommitted, New EventHandler(AddressOf ComboBox_SelectionChangeCommitted)
End If
End If
End Sub
Private Sub ComboBox_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim combo As ComboBox = CType(sender, ComboBox)
Console.WriteLine("Row: {0}, Value: {1}", DataGridView1.CurrentCell.RowIndex, combo.SelectedItem)
End Sub
相關問題
- 1. 選擇改變事件
- 2. 選擇在更改事件
- 3. JavaScript和選擇框改變事件
- 4. WPF DataGridComboBoxColumn DropdownClosed事件
- 5. 選擇更改事件
- 6. 將事件添加到DataGridComboBoxColumn
- 7. DropKick在IE上選擇更改事件
- 8. Backbone.js的選擇更改事件在Firefox
- 9. setTimeout在選擇框更改事件
- 10. 通過選擇更改改變事件的佔位符文本
- 11. 階:雙「選擇改變」事件引發的ListView控件組件
- 12. 下拉選擇值改變事件在vtiger crm
- 13. jQuery的改變事件不選擇選項
- 14. 選擇改變
- 15. 觸發改變在多選擇選擇
- 16. 當選擇發生變化時,DataGridComboBoxColumn會丟失其內容
- 17. 選擇 - 在更改事件後觸發打開事件
- 18. 觸發事件,當web瀏覽器文本選擇改變
- 19. Yii的顏色選擇器改變事件的問題
- 20. 改變與選擇TD值,而不是傳播事件
- 21. 選擇元素的事件偵聽器沒有改變值
- 22. Primefaces AJAX事件改變一個菜單中選擇
- 23. 劍道網格行選擇改變事件?
- 24. 上選擇改變
- 25. 選擇不改變
- 26. 當選擇被清除時選擇選擇插件「更改」事件
- 27. 更改事件觸發的選擇框
- 28. GWT:CheckBoxCell和選擇更改事件
- 29. UWP- windows.ui.xaml.controls.flipview選擇更改事件?
- 30. 更改onbeforeunload事件的默認選擇
我早就在等待一個解決方案,以及,謝謝你完美的作品! – 2012-04-02 16:06:59
綜合答案。大拇指和比分! – 2016-01-10 11:24:10