I have a One DataGridView it has Two DataGridViewComboBoxColumn i want to handle selectedindexchanged event of both differently
how can i achieve ?
IN Winform VB.net
I have a One DataGridView it has Two DataGridViewComboBoxColumn i want to handle selectedindexchanged event of both differently
how can i achieve ?
IN Winform VB.net
It's possible to differentiate between which combobox-column was clicked by the columnindex. Small example:
Private Sub dataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles dataGridView1.EditingControlShowing
If TypeOf e.Control Is ComboBox Then
If dataGridView1.CurrentCell.ColumnIndex = 1 Then
Dim cb As ComboBox = TryCast(e.Control, ComboBox)
'remove handler if it was added before
RemoveHandler cb.SelectedIndexChanged, AddressOf ColumnCombo1SelectionChanged
AddHandler cb.SelectedIndexChanged, AddressOf ColumnCombo1SelectionChanged
ElseIf dataGridView1.CurrentCell.ColumnIndex = 2 Then
Dim cb As ComboBox = TryCast(e.Control, ComboBox)
'remove handler if it was added before
RemoveHandler cb.SelectedIndexChanged, AddressOf ColumnCombo2SelectionChanged
AddHandler cb.SelectedIndexChanged, AddressOf ColumnCombo2SelectionChanged
End If
End If
End Sub
Private Sub ColumnCombo1SelectionChanged(sender As Object, e As EventArgs)
Dim sendingComboEdit = TryCast(sender, DataGridViewComboBoxEditingControl)
Dim selectedValue As Object = sendingComboEdit.SelectedValue
End Sub
Private Sub ColumnCombo2SelectionChanged(sender As Object, e As EventArgs)
Dim sendingComboEdit = TryCast(sender, DataGridViewComboBoxEditingControl)
Dim selectedValue As Object = sendingComboEdit.SelectedValue
End Sub