Results 1 to 15 of 15

Thread: [RESOLVED] Autocomplete TextBox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Resolved [RESOLVED] Autocomplete TextBox

    Hi

    I've got a basic email application set up, and I'd like the "To" field (TextBox1) to be an autocomplete textbox.

    I'd also like the user to be able to edit what their contacts are, and so be able to add named to the autocomplete suggestions.

    I can get TextBox1's autocomplete suggestion to come from TextBox2's current Text - however this means I can only have one name as a suggested contact.

    Ideally, something like a list box would be ideal, so the user can add and remove names, and this list would then provide the source for the autocomplete.

    Thanks for the help,

    M

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Autocomplete TextBox

    Hope this helps
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: Autocomplete TextBox

    Thank you for the link!

    For some reason, I'm having difficulty making it work - I think I'm assigning the wrong names to the wrong things. Would you be able to clarify which textboxes I should name as what?

    Many thanks

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: Autocomplete TextBox

    You wish Textbox1 to have its autocompletesource by the entries of Listbix1. The example in the other thread needs no editing.

    The listbox will need to be populated of course.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: Autocomplete TextBox

    My ListBox is being populated when the form is running, by the user entering the info into TextBox2, pressing a button and the option appearing in the listbox.

    However, without editing the code, TextBox1 will not autocomplete.

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: Autocomplete TextBox

    On form load make sure you set properties: (Also can be done in the properties window)

    Code:
    Me.txtEmailUser.AutoCompleteSource = AutoCompleteSource.CustomSource
    Me.txtEmailUser.AutoCompleteMode = AutoCompleteMode.Suggest
    For example when adding a new entry.

    vb Code:
    1. Private Sub btnAddNewSuggest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNewSuggest.Click
    2.  
    3. If String.IsNullOrEmpty(Me.txtAddToList.Text) Then
    4.      Exit Sub
    5. End If
    6.  
    7. Me.ListBox1.Items.Add(Me.txtAddToList.Text)
    8. Me.txtAddToList.Clear()
    9. Me.SetCompleteList(Me.txtEmailUser, Me.ListBox1.Items)
    10.  
    11. End Sub

  7. #7
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: Autocomplete TextBox

    Here is an example
    Attached Files Attached Files

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: Autocomplete TextBox

    Thank you! this is great. Thanks for your time and help!

  9. #9
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: [RESOLVED] Autocomplete TextBox

    One thing i forgot to mention was if you wanted to save your contacts. revised a little but would suggest using a ListView.
    Attached Files Attached Files

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: [RESOLVED] Autocomplete TextBox

    That is even better! Thank you for being so willing and helpful

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: [RESOLVED] Autocomplete TextBox

    Hi, sorry to bother again...

    i've just about got your second load of code into my own project...however, one build error occurring:

    "GetItemText is not a member of System.Windows.Forms.Listview"...

    Cannot work out what I've not done right?

    Thanks again for your continued help! I appreciate it loads.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: [RESOLVED] Autocomplete TextBox

    (the line appears just before the very end of the code)

  13. #13
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: [RESOLVED] Autocomplete TextBox

    My project uploaded is using a listbox, you are using a list view.

    Code:
    For Each contact As ListViewItem In Me.lvwMyListView.Items
         MessageBox.Show(contact.Text)
    Next
    So replace MessageBox with sw.writeline(contact.text)
    Last edited by ident; Dec 11th, 2011 at 01:32 PM.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: [RESOLVED] Autocomplete TextBox

    Thanks for your prompt reply and apologies for mine taking ages!

    Can you clarify where that new code should go?

    I'm using the project you uploaded which was designed for saving contacts, and am getting the "GetItemText is not a member of System.Windows.Forms.Listview"... error.

    And when I swap in the

    vb Code:
    1. For Each contact As ListViewItem In Me.lvwMyListView.Items
    2.      MessageBox.Show(contact.Text)
    3. Next

    where I think it should be, it means the form no longer works.

    Apologies for the hassle,

    Thanks for your help

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: [RESOLVED] Autocomplete TextBox

    Apologies! have just sorted it

    Thanks again!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width