6 Replies - 6547 Views - Last Post: 14 September 2010 - 07:39 AM Rate Topic: -----

#1 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1387
  • View blog
  • Posts: 4,465
  • Joined: 25-September 09

AutoComplete TextBox

Posted 13 September 2010 - 06:50 AM

I have a small problem with my AutoComplete Textbox in that it doesn't replace what I type with the item from the drop down list. This is hard to explain so I will start off with the AutoComplete of the combobox and how it works.

If I create a combobox with the following listitems (pay attention to case as this is the actual problem)

Item1
Item2
Production1
Production2

Now I can set my AutocompleteSource to ListItems and when I begin typing into a combobox I get a list of matches (Using SuggestAppend)

So if I type i (lowercase) I get a list containing Item1 and Item2 with tem1 added and selected for overtyping in my combobox text. Now if I press Tab or Enter, My combobox.text is updated with Item1 with the proper casing from the list even though I typed a lowercase i. This is not how it is working in the textbox. Using the following code:
Dim mySource As New AutoCompleteStringCollection
        mySource.AddRange({"Item1", "Item2", "Production1", "ProductionItem2"})
        TextBox1.AutoCompleteCustomSource = mySource
        TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
        TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend


When I begin typing in the textbox, again, the list drops down. And again, when I type a lowercase i, I get a list containing Item1 and Item2 with tem1 filled in to my textbox. Now if I press enter or tab, my textbox is filled with item1 instead of Item1 as it did with the combobox.

My question is:
Is there a way to ensure that the text in the textbox matches the actual case of the item in the customsource? I can click the item in the dropdown and it appears in the textbox just fine. But I don't want to force my users to have to do that.

Is This A Good Question/Topic? 0
  • +

Replies To: AutoComplete TextBox

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 959
  • View blog
  • Posts: 3,688
  • Joined: 02-July 08

Re: AutoComplete TextBox

Posted 13 September 2010 - 07:10 AM

Just use the Suggest option then it will only insert the cased version in the drop down if they pick it, otherwise it will be what they type.

This post has been edited by hawkvalley1: 13 September 2010 - 07:10 AM

Was This Post Helpful? 1
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1387
  • View blog
  • Posts: 4,465
  • Joined: 25-September 09

Re: AutoComplete TextBox

Posted 13 September 2010 - 07:25 AM

Thanks HawkValley but that doesn't limit them to only items in the listbox dropdown. This is really more of a cosmetic issue because the item will still be found but when Printing the end result, I would like the actual text.

I just thought there might be a way to send focus to the list while typing much like the autocomplete does automatically on a combobox.

I guess I could just create my own listbox and handle all of this myself then I could find in the list as the user is typing and replace the match with the listitem upon leaving the textbox.

This post has been edited by CharlieMay: 13 September 2010 - 07:29 AM

Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 959
  • View blog
  • Posts: 3,688
  • Joined: 02-July 08

Re: AutoComplete TextBox

Posted 13 September 2010 - 07:31 AM

Well you can always check on the Leave event or even the textchanged event to see if the text matches an item in your list. Or maybe even the keydown event and cancel before they can add the next char. Or use a custom dialog box with a listbox of your choices that they can enter.
Was This Post Helpful? 0
  • +
  • -

#5 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 288
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: AutoComplete TextBox

Posted 14 September 2010 - 01:50 AM

Hi CharlieMay,

Did this for the textbox1.leave event... Don't know how it will behave (performance wise) with lot's of records though...

Private Sub TextBox1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
        For Each MyString As String In TextBox1.AutoCompleteCustomSource
            If UCase(MyString) = UCase(TextBox1.Text) Then
                TextBox1.Text = MyString
            End If
        Next
    End Sub



basically compare it in upper case (or lower case if you want) and if it's the same then use the item form the list rather the textbox.
Was This Post Helpful? 1
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1387
  • View blog
  • Posts: 4,465
  • Joined: 25-September 09

Re: AutoComplete TextBox

Posted 14 September 2010 - 05:50 AM

Thanks!! motcom that worked perfectly, I just loaded the custom source with 10000 records and it responded perfectly. My real data is only about 300 items so I don't think performance will be an issue.
Was This Post Helpful? 0
  • +
  • -

#7 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 288
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: AutoComplete TextBox

Posted 14 September 2010 - 07:39 AM

good to know, i haven't loaded so many records yet, but as with datagridview and lots of rows and columns it always tends to get slow.. especially when column resizing and re-ordering... anyhow good to know that it works on autocomplete...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1