Results 1 to 10 of 10

Thread: [RESOLVED][2005] Auto-Complete a combo box?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    184

    [RESOLVED][2005] Auto-Complete a combo box?

    Can anyone give me an idea as to how to make a Combo box auto-complete? The combo boxes are being filled from a SQL table, which works fine. I am not sure how to make them auto-complete when a letter is typed.

    Also, in the db, there are some records with corresponding characters.
    For example, one record might be F110 and another record might be S110. The end users want to be able to use 10-key to select items, so rather than typing F110 to find the correct db record, is there a way to make each one distinguished?

    Thanks.
    Last edited by o9z1; Nov 8th, 2006 at 05:29 PM.

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Auto-Complete a combo box?

    Try to set these properties of the combo box and try.
    Attached Images Attached Images  

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Auto-Complete a combo box?

    Quote Originally Posted by o9z1
    Can anyone give me an idea as to how to make a Combo box auto-complete? The combo boxes are being filled from a SQL table, which works fine. I am not sure how to make them auto-complete when a letter is typed.

    Also, in the db, there are some records with corresponding characters.
    For example, one record might be F110 and another record might be S110. The end users want to be able to use 10-key to select items, so rather than typing F110 to find the correct db record, is there a way to make each one distinguished?

    Thanks.
    After filling your combobox, you just need to set these properties
    VB Code:
    1. With ComboBox1
    2.             .AutoCompleteSource = AutoCompleteSource.ListItems 'The source is the items in combobox
    3.             .AutoCompleteMode = AutoCompleteMode.SuggestAppend 'Change the mode such that it best suits your need
    4.         End With

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    184

    Re: [2005] Auto-Complete a combo box?

    Thanks guys. Stan, your solution worked exactly how I wanted it to. I appreciate it.

    Is there a way to distinguish between the different letters of records?

    So if F110 and S110 exist, the end user doesn't want to type the letters, but use the 10-key? There are roughly 500 different entries into the table, so there might be 100 instances of the same number used but a different preceding letter...ie. F110, S110, F111, S111, etc.

  5. #5
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Auto-Complete a combo box?

    So what was so different my example from stanav? Instead of coping and pasting codes you need to understand them. If you check the properties on the design time you would see all the values you could set for “AutoCompleteMode” and choose one that suits you. Also I don’t understand why you want to make your code bigger, more complicated that will be difficult to read, where you could simply set the properties on design time since you will set it only ones.

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Auto-Complete a combo box?

    I can see a valid reason, VBDT. If the control is dynamically created at run time, it won't be available in design view but it will be in code view

  7. #7
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Auto-Complete a combo box?

    yes but we don't know that!

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    184

    Re: [2005] Auto-Complete a combo box?

    I didn't just copy and paste the code as you implied. Actually the first thing I did when I read the examples, was looked up information on each item and foudn this:

    The AutoCompleteSource Enumeration has following members:

    * AllSystemResources - Specifies the equivalent of FileSystem and AllUrl as the source. This is the default value when AutoCompleteMode has been set to a value other than the default.
    * AllUrl - Specifies the equivalent of HistoryList and RecentlyUsedList as the source.
    * CustomSource - Specifies strings from a built-in AutoCompleteStringCollection as the source.
    * FileSystem - Specifies the file system as the source.
    * FileSystemDirectories - Specifies that only directory names and not file names will be automatically completed.
    * HistoryList - Includes the Uniform Resource Locators (URLs) in the history list.
    * ListItems - Specifies that the items of the ComboBox represent the source.
    * None - Specifies that no AutoCompleteSource is currently in use. This is the default value of AutoCompleteSource.
    * RecentlyUsedList - Includes the Uniform Resource Locators (URLs) in the list of those URLs most recently used.

    The AutoCompleteMode enumeration has following members:

    * Append - Appends the remainder of the most likely candidate string to the existing characters, highlighting the appended characters.
    * None - Disables the automatic completion feature for the ComboBox and TextBox controls.
    * Suggest - Displays the auxiliary drop-down list associated with the edit control. This drop-down is populated with one or more suggested completion strings.
    * SuggestAppend - Applies both Suggest and Append options.

    I realize that both do the same thing, but just selecting an option in the properties window does not really do any more than copy/pasting code. You said "try to set these properties of the combo box and try again" with no explanation. With Stan's code samples, I was able to search and see what each part did.

    I am not a college student needing a grade, I am an IT professional trying my best to learn VB.net on my own time. Just because YOU think someone is copying and pasting code to get the quick fix, you could be wrong. That does me absolutely no good in determining my solution. If you want to see what I had done previously to auto complete my combo box, here it is....I ran into a problem with the code though as if the values were entered too quick, the auto complete wouldn't respond quick enough.

    Code:
     'AUTO COMPLETE CODE TO FILL IN FINISHERLOC COMBO BOX
        Private Sub cboFinisherLoc_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboFinisherLoc.KeyUp
            Dim iIndex As Integer
            Dim sActual As String
            Dim sFound As String
            Dim bMatchFound As Boolean
    
            
            If Not cboFinisherLoc.Text = "" Then 'if the text is not blank then only proceed
       
                If e.KeyCode = Keys.Back Then
                    cboFinisherLoc.Text = Mid(cboFinisherLoc.Text, 1, Len(cboFinisherLoc.Text) - 1)
                End If
    
                If ((e.KeyCode = Keys.Left) Or _
                 (e.KeyCode = Keys.Right) Or _
                 (e.KeyCode = Keys.Up) Or _
                 (e.KeyCode = Keys.Down) Or _
                 (e.KeyCode = Keys.PageUp) Or _
                 (e.KeyCode = Keys.PageDown) Or _
                 (e.KeyCode = Keys.Home) Or _
                 (e.KeyCode = Keys.End)) Then
                    Return
                End If
    
                Do
                   
                    sActual = cboFinisherLoc.Text
                    iIndex = cboFinisherLoc.FindString(sActual)
                   
                    If (iIndex > -1) Then 
                        sFound = cboFinisherLoc.Items(iIndex).ToString()
                     
                        cboFinisherLoc.SelectedIndex = iIndex
                       
                        cboFinisherLoc.SelectionStart = sActual.Length
                        cboFinisherLoc.SelectionLength = sFound.Length
                        bMatchFound = True
                    Else 
    
                        If sActual.Length = 1 Or sActual.Length = 0 Then
                            cboFinisherLoc.SelectedIndex = 0
                            cboFinisherLoc.SelectionStart = 0
                            cboFinisherLoc.SelectionLength = Len(cboFinisherLoc.Text)
                            bMatchFound = True
    
                        Else
                            
                            cboFinisherLoc.SelectionStart = sActual.Length - 1
                            cboFinisherLoc.SelectionLength = sActual.Length - 1
                            cboFinisherLoc.Text = Mid(cboFinisherLoc.Text, 1, Len(cboFinisherLoc.Text) - 1)
                    
                        End If
                    End If
                Loop Until bMatchFound
            End If
        End Sub

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    184

    Re: [2005] Auto-Complete a combo box?

    And also, before you even posted, I acknowledged that both worked fine.....and the reason I left you both reputation.

  10. #10
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Auto-Complete a combo box?

    My explanation was “try to set these properties of the combo box and try again” because if you did and found out it works then it would be natural to ask the question WHY? Then you will look for it on dynamic help which will give you more info then anyone of us here. Anyway I am glad that it worked. Peace!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width