We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Modify a datagridview combobox which is editable to not display the first item automatically..

si2030
si2030 asked
on
Medium Priority
223 Views
Last Modified: 2012-05-06
Hi Experts,

I have a datagridviewcombobox which I have made editable.

The problem is, when I go and click on it I find it automatically populates the combobox with the first item in the drop down. See the following to see what I mean

http://www.screencast.com/users/si2030/folders/Jing/media/9c8d310d-b6c0-4e09-93b4-ecff36cae8b8 

I have used the following code to make it editable. - see the code area.

I want to click on any combobox in this column and be able to type without starting with the first item in it.

I thought you might be able to use selectionStart but I dont know how to apply it - if that is the answer..
Private Sub dgvCreditorInvoiceDetail_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvCreditorInvoiceDetail.EditingControlShowing
 
      If (TypeOf e.Control Is DataGridViewComboBoxEditingControl) Then
 
            Dim cmb As DataGridViewComboBoxEditingControl = CType(e.Control, DataGridViewComboBoxEditingControl)
 
            If (Not cmb Is Nothing) And (dgvCreditorInvoiceDetail.CurrentCellAddress.X = 0) Then
 
                cmb.DropDownStyle = ComboBoxStyle.DropDown
 
            End If
 
        End If
 
    End Sub

Open in new window

Comment
Watch Question

IT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
Try to change it to this:

        If (TypeOf e.Control Is DataGridViewComboBoxEditingControl) Then
 
            Dim cmb As DataGridViewComboBoxEditingControl = CType(e.Control, DataGridViewComboBoxEditingControl)
 
            If (Not cmb Is Nothing) And (dgvCreditorInvoiceDetail.CurrentCellAddress.X = 1) Then
 
                cmb.DropDownStyle = ComboBoxStyle.DropDown
                cmb.SelectedIndex = -1
            End If
 
        End If

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Perfect and timely!!

Thanks jpaulino..

SImon
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Glad I could help!
jpaulino
 
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.