Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7771445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:39:17+00:00 2026-06-01T16:39:17+00:00

I have a problem with the auto-complete behaviour of comboboxes in VB.NET (with the

  • 0

I have a problem with the auto-complete behaviour of comboboxes in VB.NET (with the .NET framework 2.0).

I am using a combobox to type in numeric values, and its DropDown list to suggest possible numeric values. This list is sorted in ascending order, for example {“10″,”92”, “9000”, “9001”}.

The combobox properties are set as follow:

  • AutoCompleteMode: SuggestAppend
  • AutoCompleteSource: ListItems
  • DropDownStyle: DropDown
  • Sorted: False

The DropDown list is simply filled like this:

  • myCombobox.Items.Add(“10”)
  • myCombobox.Items.Add(“92”)
  • myCombobox.Items.Add(“9000”)
  • myCombobox.Items.Add(“9001”)

When I don’t type anything, the order of values of the DropDown list is correct, in original/ascending order. However, when I start typing something, the suggested values in the DropDown list get sorted (alphanumerically): if I type “9”, the list of suggestions becomes {“9000”, “9001”, “92”}.

I would like to prevent this behaviour to get the values of the list in the original/ascending order. I can’t figure out how…

A possible work-around would be to pad with zeroes the values in the list, e.g. {“0010”, “0092”, “9000”, “9001”} but I would like to avoid this.

Edit:

As suggested by bendataclear, one can use a list box to display the suggestions.
This will work for small lists but doesn’t scale well to large lists. It may be useful for some applications. Based on the code given by bendataclear, I made it work this way:


Private Sub ComboBox1_KeyUp(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp

    Dim cursorPos As Integer = ComboBox1.SelectionStart

    ListBox1.Items.Clear()

    For Each s In ComboBox1.Items
        If s.StartsWith(ComboBox1.Text) Then
            ListBox1.Items.Add(s)
        End If
    Next

    If ListBox1.Items.Count > 0 And ComboBox1.Text.Length > 0 Then
        ComboBox1.Text = ListBox1.Items(0)
        ComboBox1.SelectionStart = cursorPos
        ComboBox1.SelectionLength = 0
    End If

End Sub

The code has not been thoroughly tested and can be improved, but the main idea is there.

Edit 2:

Using DataGridView leads to better performance; it was sufficient for me. Thanks bendataclear.

Just out of curiosity, any other answer is welcomed 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:39:18+00:00Added an answer on June 1, 2026 at 4:39 pm

    Seems to be an issue when the combo box displays the data, as even if you set a custom source it re-orders alphabetically:

    ComboBox1.Items.Add("10")
    ComboBox1.Items.Add("92")
    ComboBox1.Items.Add("9000")
    ComboBox1.Items.Add("9001")
    
    ComboBox1.AutoCompleteCustomSource.Add("10")
    ComboBox1.AutoCompleteCustomSource.Add("92")
    ComboBox1.AutoCompleteCustomSource.Add("9000")
    ComboBox1.AutoCompleteCustomSource.Add("9001")
    
    ComboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
    

    I think the only way I can think of is to create your own autocomplete something like (untested):

    Dim cbotxt As String = ComboBox1.Text
    Dim key As String
    
    key = ChrW(e.KeyCode)
    
    
    ListBox1.Items.Clear()
    
    For Each i In ComboBox1.Items
    
        Dim s As String = i.ToString()
    
        If s.StartsWith(ComboBox1.Text & key) Then
    
            ListBox1.Items.Add(s)
    
    
        End If
    
    Next
    
    If ListBox1.Items.Count > 0 Then
        ListBox1.Visible = True
        ComboBox1.Text = ListBox1.Items(0)
    
    End If
    

    Edit:

    A good approach for many items (I’m using for 10000+ in an application):

    First change from a list box to a datagridview.
    Then declare a list of strings and fill with values you want to autocomplete

     Dim Numberlist as List<Of String>
    
    ' Fill List using Numberlist.Add("String")
    

    Then in the text change property:

    Filter = NumberList.FindAll(AddressOf checkNum)
    
    DataGridView1.DataSource = Filter
    

    And add the function to check the strings.

    Function checkNum(ByVal b As String) As Boolean
    
        If b.StartsWith(ComboBox1.Text) Then
            Return True
        Else
            Return False
        End If
    
    End Function
    

    This method runs on my machine with 10k items faster than I can type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey Guys. I have got a problem on using the jquery auto-complete plugin.my problem
I've created a simple auto-complete control using JQuery UI. I have a default value
I have a css problem with jquery / jquery ui / auto complete <script
I have implemented the auto complete functionality using the Ajax.autocompleter function of the Scriptaculous
I have A problem regarding Converting Xaml to C# , I m using Auto
I have an auto complete box on my site. I'm using Tokeninput . When
I have a problem with using facet. I need autocomplete and for this I
i have a problem with auto incremental primary keys.. when im adding a student
I have a big problem. I use excel auto filter function, at the end
I have problem with my query on C, I’m using the oci8 driver. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.