Change AutoComplete to "full text" search?

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

Guest

Is it possible to change the autocomplete behaviour to search for the word
instead of just checking for the prefix?

For example, if I have the following items:

Big Mac
Quarter Pounder
Cheeseburger

and someone types: Pounder, it should display "Quarter Pounder"?

Thanks!
 
Is it possible to change the autocomplete behaviour to search for the word
instead of just checking for the prefix?

For example, if I have the following items:

Big Mac
Quarter Pounder
Cheeseburger

and someone types: Pounder, it should display "Quarter Pounder"?

Thanks!

For instance, try this:

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "Pounder" Then
TextBox1.Text = "Quarter Pounder"
End If
End Sub
 
For instance, try this:

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "Pounder" Then
TextBox1.Text = "Quarter Pounder"
End If
End Sub

How is that going to help me in an autocomplete situation?
 
How is that going to help me in an autocomplete situation?

I know it's not directly related to AutoComplete property but this can
give you an urgent solution that makes text field as you wish if typer
writes "Pounder" then textbox becomes "Ouarter Pounder" because of
textbox's text_changed event, i hope you tried it.
 
I know it's not directly related to AutoComplete property but this can
give you an urgent solution that makes text field as you wish if typer
writes "Pounder" then textbox becomes "Ouarter Pounder" because of
textbox's text_changed event, i hope you tried it.

Unfortunately its not what I'm really looking for - I would like to have
the autocomplete list populated with suggestions like what Google Suggests
does.

If I only handle the TextChange event ... it'll be too much of a kudlge to
be rewriting the user's input on the fly? I rather be able to display the
suggestions in the autocomplete portion of the control.

But, thanks for the suggestion!
 
Spam Catcher said:
(e-mail address removed):


Unfortunately its not what I'm really looking for - I would like to have
the autocomplete list populated with suggestions like what Google Suggests
does.

If I only handle the TextChange event ... it'll be too much of a kudlge to
be rewriting the user's input on the fly? I rather be able to display the
suggestions in the autocomplete portion of the control.

But, thanks for the suggestion!


Textbox has its own Autocomplete functionallity.

As an example:

Me.TextBox1.AutoCompleteCustomSource.AddRange(New String() {"One", "Two",
"Three"})
Me.TextBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest
Me.TextBox1.AutoCompleteSource =
System.Windows.Forms.AutoCompleteSource.CustomSource

The AutoCompleteCustomSource can be populated in pretty much any way you
want as long as it is an array of strings. Get it from database or where
ever.

Hope this is what you are looking for
Lloyd Sheen
 
Textbox has its own Autocomplete functionallity.

As an example:

Me.TextBox1.AutoCompleteCustomSource.AddRange(New String() {"One",
"Two", "Three"})
Me.TextBox1.AutoCompleteMode =
System.Windows.Forms.AutoCompleteMode.Suggest
Me.TextBox1.AutoCompleteSource =
System.Windows.Forms.AutoCompleteSource.CustomSource

The AutoCompleteCustomSource can be populated in pretty much any way
you want as long as it is an array of strings. Get it from database
or where ever.

Hope this is what you are looking for

Yes, I know - but AutoComplete only search the PREFIX of the entries.

As you see in my example, if you populate the autocomplete source with:

Big Mac
Quarter Pounder
Cheeseburger

and someone types in Pounder... it won't display Quarter Pounder as a
suggestion...

That's my problem - not how to populate the autocomplete datasource.

I want to override/rewire the AutoComplete functionality in Winform
Controls - if someone can point me in the right direction, that'll be
great!

Thanks.
 
Spam Catcher said:
Yes, I know - but AutoComplete only search the PREFIX of the entries.

As you see in my example, if you populate the autocomplete source with:

Big Mac
Quarter Pounder
Cheeseburger

and someone types in Pounder... it won't display Quarter Pounder as a
suggestion...

That's my problem - not how to populate the autocomplete datasource.

I want to override/rewire the AutoComplete functionality in Winform
Controls - if someone can point me in the right direction, that'll be
great!

Thanks.


Ok try this.

Instead of a textbox use a combobox. Set

Me.ComboBox1.AutoCompleteMode =
System.Windows.Forms.AutoCompleteMode.Suggest
Me.ComboBox1.AutoCompleteSource =
System.Windows.Forms.AutoCompleteSource.ListItems

On the form:

Me.KeyPreview = True

Now the code:

Dim myList As New List(Of String)

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Dim t As String = String.Empty
If Not Char.IsLetter(e.KeyChar) Then
Exit Sub
End If
If Me.ComboBox1.Focused Then
Dim tmp As String
Dim tmp2 As String
Dim ss As Integer = ComboBox1.SelectionStart
tmp = ComboBox1.Text.Substring(0, ComboBox1.SelectionStart) +
e.KeyChar.ToString + ComboBox1.Text.Substring(ComboBox1.SelectionStart)
tmp2 = tmp.ToUpper
ComboBox1.Items.Clear()
For Each s As String In myList
If s.ToUpper.Contains(tmp2) Then
ComboBox1.Items.Add(s)
End If
Next
ComboBox1.Text = tmp
ComboBox1.SelectionStart = ss + 1
If ComboBox1.Items.Count > 0 Then
ComboBox1.DroppedDown = True
End If
End If
e.Handled = True
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
myList.Add("Big Mac")
myList.Add("Little Mac")
myList.Add("Quarter Pounder")
myList.Add("Cheeseburger")
End Sub

The loading of the items I can leave to you and you will notice that I have
a filter
If Not Char.IsLetter(e.KeyChar) Then
Exit Sub
End If
in sub. You may want to change this to handle other characters than letters
but you will want to filter out handling the control characters.

Hope this helps
Lloyd Sheen
 
Lloyd Sheen said:
Ok try this.

Instead of a textbox use a combobox. Set

Me.ComboBox1.AutoCompleteMode =
System.Windows.Forms.AutoCompleteMode.Suggest
Me.ComboBox1.AutoCompleteSource =
System.Windows.Forms.AutoCompleteSource.ListItems

On the form:

Me.KeyPreview = True

Now the code:

Dim myList As New List(Of String)

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Dim t As String = String.Empty
If Not Char.IsLetter(e.KeyChar) Then
Exit Sub
End If
If Me.ComboBox1.Focused Then
Dim tmp As String
Dim tmp2 As String
Dim ss As Integer = ComboBox1.SelectionStart
tmp = ComboBox1.Text.Substring(0, ComboBox1.SelectionStart) +
e.KeyChar.ToString + ComboBox1.Text.Substring(ComboBox1.SelectionStart)
tmp2 = tmp.ToUpper
ComboBox1.Items.Clear()
For Each s As String In myList
If s.ToUpper.Contains(tmp2) Then
ComboBox1.Items.Add(s)
End If
Next
ComboBox1.Text = tmp
ComboBox1.SelectionStart = ss + 1
If ComboBox1.Items.Count > 0 Then
ComboBox1.DroppedDown = True
End If
End If
e.Handled = True
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
myList.Add("Big Mac")
myList.Add("Little Mac")
myList.Add("Quarter Pounder")
myList.Add("Cheeseburger")
End Sub

The loading of the items I can leave to you and you will notice that I
have a filter
If Not Char.IsLetter(e.KeyChar) Then
Exit Sub
End If
in sub. You may want to change this to handle other characters than
letters but you will want to filter out handling the control characters.

Hope this helps
Lloyd Sheen

Sorry for last one I have a much simpler one:

Just one combobox. No items. No autosuggest settings.


Then the following code:


Public Class Form1

Dim myList As New List(Of String)
Dim shownList As New List(Of String)
Dim ss As Integer

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
myList.Add("Big Mac")
myList.Add("Little Mac")
myList.Add("Quarter Pounder")
myList.Add("Cheeseburger")
End Sub

Private Sub ComboBox1_DropDown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ComboBox1.DropDown
SetNewItems()
End Sub

Private Sub SetNewItems()
ComboBox1.Items.Clear()
For Each s As String In shownList
ComboBox1.Items.Add(s)
Next
ComboBox1.SelectionStart = ss
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
If shownList.Count > 0 Then
ss = ComboBox1.SelectionStart
If ComboBox1.DroppedDown = True Then
SetNewItems()
Else
ComboBox1.DroppedDown = True
End If
End If
End Sub

Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ComboBox1.TextChanged
Dim tmp2 As String = ComboBox1.Text.ToUpper
'ComboBox1.DroppedDown = False
shownList.Clear()
If tmp2 <> String.Empty Then
For Each s As String In myList
If s.ToUpper.Contains(tmp2) Then
shownList.Add(s)
End If
Next
End If
If shownList.Count > 0 Then
Timer1.Interval = 100
Timer1.Enabled = True
Else
ComboBox1.DroppedDown = False
End If
End Sub
End Class

Think this is it.
Lloyd Sheen
 
Back
Top