Autocompleting Dropdown List


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Autocompleting Dropdown List

  1. #1
    Jeff Johnson Guest

    Autocompleting Dropdown List


    I tried this:

    http://www.codeproject.com/vb/net/au...e_combobox.asp

    And it's not quite what I want. The combobox from the code project autocompletes...
    but you can still type in anything you want. (Sort of like an Excel column.)

    What I want is to have the autocomplete feature, but restrict the options
    to what we have in the list. (No matter what they type, we've got an item
    from the list selected.)

    The drop down list option on the VB.Net standard combobox is almost what
    I want: it will cycle through the items starting with "a" each time that
    you press "a." If you type "b" but goes to the first item in the list starting
    with "b." (This can be annoying if you have 30 items starting with "a" because
    it forces you to use the mouse to scroll and find your item every time OR
    type "a" 30 times to get your item. No good for data entry apps!)

    Is a combox like what I want "out there" allready??

    Thanks...

  2. #2
    Tim Hitchings \(Infragistics\) Guest

    Re: Autocompleting Dropdown List

    Jeff Johnson wrote:
    > Is a combox like what I want "out there" allready??



    Try the Infragistics NetAdvantage Suite
    http://www.infragistics.com




  3. #3
    Jeff Johnson Guest

    Re: Autocompleting Dropdown List


    It wasn't hard to fix up the code to make it do what I want.

    Here's what I changed. (Maybe not the most elegant code, but it works....)




    Private Sub ComboBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs)
    Handles ComboBox1.Leave

    Dim recRowView As DataRowView

    AutoCompleteCombo_Leave(ComboBox1)

    'OPTIONAL: Now you can do some extra handling if you want

    'Get the Selected Record from my Data Bound Combo (Return Type is
    DataRowView)
    recRowView = ComboBox1.SelectedItem

    Dim e2 As New System.Windows.Forms.KeyEventArgs(Keys.A)

    If recRowView Is Nothing Then
    'Item is not in the list...

    Dim str As String = ComboBox1.Text
    If Len(str) > 5 Then
    str = str.Substring(0, 5)
    Else
    str = str.Substring(0, Len(str) - 1)
    End If

    Do Until Not (recRowView Is Nothing)
    If Len(str) = 0 Then
    ComboBox1.SelectedIndex = 0
    Exit Sub
    End If

    ComboBox1.Text = str

    'Look it up
    AutoCompleteCombo_KeyUp(ComboBox1, e2)
    AutoCompleteCombo_Leave(ComboBox1)
    recRowView = ComboBox1.SelectedItem

    'par it down and try again
    str = str.Substring(0, Len(str) - 1)
    Loop
    End If

    End Sub



    "Jeff Johnson" <jeff.johnson@nospam.com> wrote:
    >
    >I tried this:
    >
    >http://www.codeproject.com/vb/net/au...e_combobox.asp
    >
    >And it's not quite what I want. The combobox from the code project autocompletes...
    >but you can still type in anything you want. (Sort of like an Excel column.)
    >
    >What I want is to have the autocomplete feature, but restrict the options
    >to what we have in the list. (No matter what they type, we've got an item
    >from the list selected.)
    >
    >The drop down list option on the VB.Net standard combobox is almost what
    >I want: it will cycle through the items starting with "a" each time that
    >you press "a." If you type "b" but goes to the first item in the list starting
    >with "b." (This can be annoying if you have 30 items starting with "a"

    because
    >it forces you to use the mouse to scroll and find your item every time OR
    >type "a" 30 times to get your item. No good for data entry apps!)
    >
    >Is a combox like what I want "out there" allready??
    >
    >Thanks...



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center