Combobox search question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, All
I am using .NET 2003
Combobox has textbox control over it used for the search;
txtSrh.Visible = True
txtSrh.Bounds = cboLoc.Bounds
txtSrh.Width -= 16

I have combobox search on 3 char in txtSrh_TextChanged procedure:
If txtSrh.TextLength = 3 Then
Dim i As Integer
Dim sLoc As String
Dim bFound As Boolean = False

For i = 0 To cboLoc.Items.Count - 1
sLoc = cboLoc.Items(i).ToString
If sLoc.Substring(0, 3) = txtSrh.Text.Trim Then
txtSrh.Visible = False
txtSrh.Text = ""
cboLoc.SelectedIndex = i
cboLoc.Focus()
Exit For
End If
Next

My question is how can i do the search where each additional letter
entered brings search closer to specifyed entry?

Thank you,
 
You could do something like this:-

Dim theText As String = txtSrh.Text

If theText.Length > 2 Then
Dim i As Integer
Dim sLoc As String
Dim bFound As Boolean = False

For i = 0 To cboLoc.Items.Count - 1
sLoc = cboLoc.Items(i).ToString
If sLoc.Substring(0, theText.Length) = theText.Trim Then
txtSrh.Visible = False
txtSrh.Text = ""
cboLoc.SelectedIndex = i
cboLoc.Focus()
Exit For
End If
Next

this checks on every change of the textbox contents above 2 characters in
length. Performance might be a drag though, will depend on number of items
in the combobox.

Peter
 
Thank you, it looks better then i did.

Peter Foot said:
You could do something like this:-

Dim theText As String = txtSrh.Text

If theText.Length > 2 Then
Dim i As Integer
Dim sLoc As String
Dim bFound As Boolean = False

For i = 0 To cboLoc.Items.Count - 1
sLoc = cboLoc.Items(i).ToString
If sLoc.Substring(0, theText.Length) = theText.Trim Then
txtSrh.Visible = False
txtSrh.Text = ""
cboLoc.SelectedIndex = i
cboLoc.Focus()
Exit For
End If
Next

this checks on every change of the textbox contents above 2 characters in
length. Performance might be a drag though, will depend on number of items
in the combobox.

Peter
 
Back
Top