Click here to Skip to main content
15,898,747 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I found some code here and there and was able to come up with some code to change the style of the DGVCombobox to a dropdown instead of droplist. It works fine by itself, but when I add more code in the EditingControlShowing handler to address another control type (stop user from entering anything but a decimal number in a textbox in column 3) it breaks. When I select another cell after selecting the handled textbox, the DGVCombobox stops working. If I comment out the code to handle column 3 textbox, the code for handling the combobox type works again. Am I missing something obvious?

VB
'Allow user to enter new values for ALL DataGridViewComboBox controls in the DataGridView
If (TypeOf e.Control Is DataGridViewComboBoxEditingControl) Then
    Dim cmb As DataGridViewComboBoxEditingControl = CType(e.Control, DataGridViewComboBoxEditingControl)
    If Not cmb Is Nothing Then
        cmb.DropDownStyle = ComboBoxStyle.DropDown
    End If
End If
' stop user from entering anything but a decimal number with 2 decimal places into column 3
If (TypeOf e.Control Is DataGridViewTextBoxEditingControl) Then
    If (JobComponentsDataGridView.CurrentCell.ColumnIndex = 2) Then
        Dim textBox As TextBox
        textBox = CType(e.Control, TextBox)
        If (Not (textBox) Is Nothing) Then
            AddHandler textBox.KeyPress, AddressOf DataGridViewTextColumn_KeyPress_NumericOnly
            RemoveHandler Me.JobComponentsDataGridView.EditingControlShowing, AddressOf JobComponentsDataGridView_EditingControlShowing
        End If
    End If
End If
Posted
Updated 17-Jun-11 17:23pm
v3

Try this link.....

http://www.rustemsoft.com/vbbegin.asp
 
Share this answer
 
I wonder if using DGVcombobox is too slow that can't run the program normally . Do you agree with me ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900