ComboBox

  • Thread starter Thread starter Jennyfer Barco
  • Start date Start date
J

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
 
Jennyfer said:
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top