DataGridViewComboBox下拉事件(VB.NET)
Private DataGridViewComboBox As DataGridViewComboBoxEditingControl = Nothing
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If TypeOf e.Control Is DataGridViewComboBoxEditingControl Then
Dim dgv As DataGridView = CType(sender, DataGridView)
If dgv.CurrentCell.OwningColumn.Name = "Sk6" Then
DataGridViewComboBox = CType(e.Control, DataGridViewComboBoxEditingControl)
DataGridViewComboBox.DropDownStyle = ComboBoxStyle.DropDown
AddHandler DataGridViewComboBox.SelectedIndexChanged, AddressOf DataGridViewComboBox_SelectedIndexChanged
End If
End If
End Sub
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
If Not (DataGridViewComboBox Is Nothing) Then
RemoveHandler Me.DataGridViewComboBox.SelectedIndexChanged, AddressOf DataGridViewComboBox_SelectedIndexChanged
DataGridViewComboBox = Nothing
End If
End Sub
Private Sub DataGridViewComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim cb As DataGridViewComboBoxEditingControl = CType(sender, DataGridViewComboBoxEditingControl)
Console.WriteLine(cb.SelectedItem)
Console.WriteLine(cb.Text)
End Sub