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

Autocomplete on datagridview combobox

si2030
si2030 asked
on
Medium Priority
3,591 Views
Last Modified: 2012-06-22
Hi Experts,

I have a datagridview that has as its first column is a datagridviewcombobox.

I have made this editable (thanks to those on this site) however I would like to make it so that if the user clicks on combobox and then starts typing that combobox will match the first item in the drop down list with whats been typed...

I have done this no problem with normal comboboxes however how do I trap and manage keystrokes for a particular datagridviewcombobox and use something like findstring..?


Simon
Private Sub dgvCreditorInvoiceDetail_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvCreditorInvoiceDetail.EditingControlShowing
 
        If dgvCreditorInvoiceDetail.CurrentCellAddress.X = accountComboBox.DisplayIndex Then
 
            Dim cmb As ComboBox = CType(e.Control, ComboBox)
 
            If Not cmb Is Nothing Then
 
                cmb.DropDownStyle = ComboBoxStyle.DropDown
 
                cmb.SelectedIndex = -1
 
            End If
 
        End If

Open in new window

Comment
Watch Question

Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
You can do the same way as regular comboboxes (in fact that is a common combobox)

Dim cmb As ComboBox = CType(e.Control, ComboBox)
cmb.AutoCompleteMode = AutoCompleteMode.Suggest
cmb.AutoCompleteSource = AutoCompleteSource.ListItems

Open in new window

Author

Commented:
Hi again jpaulino

Also wondering where this code goes? Not sure where this is placed.

Kind Regards

Simon
IT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
In your snippet
Private Sub dgvCreditorInvoiceDetail_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvCreditorInvoiceDetail.EditingControlShowing
 
        If dgvCreditorInvoiceDetail.CurrentCellAddress.X = accountComboBox.DisplayIndex Then
 
            Dim cmb As ComboBox = CType(e.Control, ComboBox)
            cmb.AutoCompleteMode = AutoCompleteMode.Suggest
            cmb.AutoCompleteSource = AutoCompleteSource.ListItems
 
            If Not cmb Is Nothing Then
 
                cmb.DropDownStyle = ComboBoxStyle.DropDown
 
                cmb.SelectedIndex = -1
 
            End If
 
        End If
End Sub

Open in new window

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

Ask the Experts

Author

Commented:
Hi Jpaulino

I did have it in the right place but in the dropdown list I had placed a space at the from so it never found anything..

I have another JING here.  The dropdown autocomplete list is only as wide as the box... is there a way to automatically reveal the whole dropdown?

http://www.screencast.com/users/si2030/folders/Jing/media/acf1f054-e901-4d86-9964-36bc8490932d
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Hummm .... I see!
But that's a limitation and I don't know if exists a way to achive that.
You may need to increase the column or use only one thing (code or description), if that ok for you. You can also use the code (if the user is familiar with that) and show the description on a new column.

Author

Commented:
Perhaps I could manage the process by code instead of automatically. I could control the behavour better.

Is there a way to force the datagridviewcombobox to drop the list?

I will set this question to accept solution and ask a more direct question after this...

Author

Commented:
On the money... thanks simon

Commented:
I have added datagridview with a column set to DataGridViewComboBoxColumn. I have also added
the EditingControlShowing event to set the combobox to AutoCompleteMode.Suggest and    .AutoCompleteSource = AutoCompleteSource.ListItems

My problem is that at times, when I type on the combobox, the dropdown list  shows items but of a bigger font size.  I have tried setting the font size in the EditingControlShowing  event. But it does not work. Is there a way to set a fixed font size?
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:

Hi,
You have to create a new question and maybe show a screenshot of your problem to a easy solution (if there is)
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.