Display the combo box items

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babitha162
    New Member
    • Mar 2009
    • 10

    Display the combo box items

    I have a combobox with a list of items in it. Now when the user enters a character I want the combox show the list of items that starts with the specified character. Could someone please help me solve this problem.

    Thanks in Advance
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Please show us what you have tried so far, so we can better help you with where your code is going wrong.

    Comment

    • truezplaya
      New Member
      • Jul 2007
      • 115

      #3
      i think i understand what you are trying to do, Your trying to search for each item within the combo box that contains the letters that are typed in to the combo box,

      Where abouts are you getting the items from? A database?

      If so you could just make a simple sql statement and everytime the textchanged event is launched fire up the sql

      another way would be to have a list of your items on the text changed event
      clear all the current items out of the combo
      start a for loop to go through the list
      if the item in that list contains whatever has been typed in so combo1.text
      add it to the items of the combo

      Comment

      • babitha162
        New Member
        • Mar 2009
        • 10

        #4
        Originally posted by truezplaya
        i think i understand what you are trying to do, Your trying to search for each item within the combo box that contains the letters that are typed in to the combo box,

        Where abouts are you getting the items from? A database?

        If so you could just make a simple sql statement and everytime the textchanged event is launched fire up the sql

        another way would be to have a list of your items on the text changed event
        clear all the current items out of the combo
        start a for loop to go through the list
        if the item in that list contains whatever has been typed in so combo1.text
        add it to the items of the combo
        Thanks for your suggestion

        Comment

        • aryanbs
          New Member
          • Mar 2009
          • 42

          #5
          One more information, textbox and combobox support autocomple feature, look at their property, you might be intersted in combobox with autocomplete source set to listitems, and autocomplete mode to SuggestAppend or Append or anything like that

          Comment

          • babitha162
            New Member
            • Mar 2009
            • 10

            #6
            Display the combo box items

            Originally posted by aryanbs
            One more information, textbox and combobox support autocomple feature, look at their property, you might be intersted in combobox with autocomplete source set to listitems, and autocomplete mode to SuggestAppend or Append or anything like that
            Thanks for your Suggestion
            I have set the AutoCompleteSou rce and AutoCompleteMod e properties of the combox. Now it displays the dropdown list and allows me to
            select the item from the list but is not allowing to enter a new item to the combobox text field.

            Code:
            Private Sub cbcity_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbcity.TextChanged
                    If cbcity.Text <> "" Then
                        cbcity.AutoCompleteSource = AutoCompleteSource.ListItems
                        cbcity.AutoCompleteMode = AutoCompleteMode.SuggestAppend
                    End If
                End Sub
            Please tell me where I have made the mistake

            Comment

            • aryanbs
              New Member
              • Mar 2009
              • 42

              #7
              Dont use textchanged event, just use those code in the beginning or after binding the data
              combobox.DataSo urce= YouDataSource

              and those 2 lines after that

              Comment

              • babitha162
                New Member
                • Mar 2009
                • 10

                #8
                Originally posted by aryanbs
                Dont use textchanged event, just use those code in the beginning or after binding the data
                combobox.DataSo urce= YouDataSource

                and those 2 lines after that
                Thanks. Now its working fine

                Comment

                Working...