Home All Groups Group Topic Archive Search About
Author
31 Jan 2006 5:10 PM
Jennyfer Barco
Hello I need to create a combobox and I need to be able to write the first 3
letters of the code and the combo goes to the first item that starts with
those 3 letters. Now what I can do is when I press 1 letter the combo goes
to the first record that starts with that letter. For example I have some
codes:

ABC1
ABC2
ABC3
ABD1
ABD2

if I press A it will go to the first "ABC1" but I need to press ABD and it
will go to "ABD1". I had this control in VB 6.0 where I was able to write in
the combobox.

Thanks in advance
Jennyfer

Author
31 Jan 2006 5:22 PM
Chris
Jennyfer Barco wrote:
Show quoteHide quote
> Hello I need to create a combobox and I need to be able to write the first 3
> letters of the code and the combo goes to the first item that starts with
> those 3 letters. Now what I can do is when I press 1 letter the combo goes
> to the first record that starts with that letter. For example I have some
> codes:
>
> ABC1
> ABC2
> ABC3
> ABD1
> ABD2
>
> if I press A it will go to the first "ABC1" but I need to press ABD and it
> will go to "ABD1". I had this control in VB 6.0 where I was able to write in
> the combobox.
>
> Thanks in advance
> Jennyfer
>
>

Do a search for autocomplete combobox.  There are lots of examples of
implementing this.

Chris
Author
31 Jan 2006 6:07 PM
jvb
Jennyfer,

I had found this example, place this code in the combobox's KeyPress
event.

        If Char.IsControl(e.KeyChar) Then Return

        With Me.cboBox

            Dim ToFind As String = .Text.Substring(0, .SelectionStart)
& e.KeyChar
            Dim Index As Integer = .FindStringExact(ToFind)

            If Index = -1 Then Index = .FindString(ToFind)
            If Index = -1 Then Return

            .SelectedIndex = Index
            .SelectionStart = ToFind.Length
            .SelectionLength = .Text.Length - .SelectionStart

            e.Handled = True

        End With