Autocomplete on datagridview combobox

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

si2030Asked:
Who is Participating?
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
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

0
 
Jorge PaulinoIT Pro/DeveloperCommented:
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

0
 
si2030Author Commented:
Hi again jpaulino

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

Kind Regards

Simon
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
si2030Author 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
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
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.
0
 
si2030Author 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...
0
 
si2030Author Commented:
On the money... thanks simon
0
 
mpssg130Commented:
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?
0
 
Jorge PaulinoIT Pro/DeveloperCommented:

Hi,
You have to create a new question and maybe show a screenshot of your problem to a easy solution (if there is)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.