shrinking combobox as you type

didgydont

Active member
Joined
Mar 2, 2009
Messages
37
Programming Experience
Beginner
hi all
im trying to make a combo box that shrinks as you type
VB.NET:
    Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
        ComboBox1.DroppedDown = False
        ComboBox1.DroppedDown = True
    End Sub
but then if you typed a letter that was the first letter of something in the list it would jump to it
this what i have
VB.NET:
    Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
        ComboBox1.DroppedDown = True
    End Sub

    Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp
        If e.KeyValue = 40 Or e.KeyValue = 38 Then
            ComboBox1.DroppedDown = True
        ElseIf e.KeyValue = 13 Then
            ComboBox1.DroppedDown = False
        Else
            '---------------refresh combo box on form1-----------------
            'Form1.ComboBox1.Text = ""
            ComboBox1.Items.Clear()
            RichTextBox1.Clear()
            Rec.Open("SELECT * FROM Passwords WHERE Name like '%" & ComboBox1.Text & "%' ORDER by Name", Conn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
            While Not Rec.EOF
                ComboBox1.Items.Add(Rec.Fields("Name").Value)
                Rec.MoveNext()
            End While
            Rec.Close()
            '----------------------------------------------------------
            ComboBox1.SelectionStart = ComboBox1.Text.Length
            ComboBox1.DroppedDown = True

        End If
    End Sub
 
hi all
im trying to make a combo box that shrinks as you type
VB.NET:
    Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
        ComboBox1.DroppedDown = False
        ComboBox1.DroppedDown = True
    End Sub
but then if you typed a letter that was the first letter of something in the list it would jump to it
this what i have
VB.NET:
    Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
        ComboBox1.DroppedDown = True
    End Sub

    Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp
        If e.KeyValue = 40 Or e.KeyValue = 38 Then
            ComboBox1.DroppedDown = True
        ElseIf e.KeyValue = 13 Then
            ComboBox1.DroppedDown = False
        Else
            '---------------refresh combo box on form1-----------------
            'Form1.ComboBox1.Text = ""
            ComboBox1.Items.Clear()
            RichTextBox1.Clear()
            Rec.Open("SELECT * FROM Passwords WHERE Name like '%" & ComboBox1.Text & "%' ORDER by Name", Conn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
            While Not Rec.EOF
                ComboBox1.Items.Add(Rec.Fields("Name").Value)
                Rec.MoveNext()
            End While
            Rec.Close()
            '----------------------------------------------------------
            ComboBox1.SelectionStart = ComboBox1.Text.Length
            ComboBox1.DroppedDown = True

        End If
    End Sub
Just to make sure I'm following you correctly, you want the combobox to select the first item that meets the criteria as they type into the textbox part at the top, right?
Microsoft makes a pretty good AJAX control just for this.

ComboBox Sample
Which would be a great suggestion except this is a winforms app not a webapp
 
no i dont want it to select anything the only problem is the list gets smaller but not the dropdown.height but if i try to edit the height or set it to false then true it selects the first item with that letter. wich cause problems
so if i search for fish when i press f the word fish appears in box highlited but when i get to pressing i the text in the combobox is only i unless there is a word that starts with i then when i press s the "is" is in the combobox you get the picture but if i dont try to resize the dropdown height it works fine but it has a big blank dropdown that goes off the screen even if there is only 1 item.
thanx for the help so far
 
Use something like this in event where the list changes.
VB.NET:
cb1.Height = cb1.ItemHeight * cb1.Items.Count
 
Use something like this in event where the list changes.
VB.NET:
cb1.Height = cb1.ItemHeight * cb1.Items.Count

that doesnt work i found i have to do
cb1.dropdownHeight = cb1.ItemHeight * cb1.Items.Count
but then the it does the whole earase of the first character typed i tried the autocomplete but it doesnt shorten the list and if i have Google stored and i search for google auto complete doesnt work i have to type www.googl and so on.
thanx for the help so far. would it help if i posted the source code some where ?
 
Back
Top