?
Solved

Autocomplete on datagridview combobox

Posted on 2009-02-14
9
Medium Priority
?
3,391 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

0
Comment
Question by:si2030
  • 4
  • 4
9 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 23640131
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
 

Author Comment

by:si2030
ID: 23640167
Hi again jpaulino

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

Kind Regards

Simon
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 2000 total points
ID: 23640174
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:si2030
ID: 23640208
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
 
LVL 48

Expert Comment

by:jpaulino
ID: 23640932
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
 

Author Comment

by:si2030
ID: 23643429
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
 

Author Closing Comment

by:si2030
ID: 31546881
On the money... thanks simon
0
 

Expert Comment

by:mpssg130
ID: 23865289
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
 
LVL 48

Expert Comment

by:jpaulino
ID: 23865539

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question