6 Replies - 328 Views - Last Post: 15 May 2013 - 04:28 PM Rate Topic: -----

#1 LaVeritas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 10-February 11

Adding values to AutoCompleteCustomSource doesn't work.

Posted 15 May 2013 - 01:46 AM

I have a simple textbox that containing "Names":

  • Set AutoCompleteSource to "CustomSource" (in Properties of the textBox)
  • AutoCompleteMode to "SuggestAppend" (in Properties of the textBox)


If I try to manually add a value to the AutoCompleteCustomSource-Collection, it works. But now I tried this:

NameTextBox.AutoCompleteCustomSource.Add(NameTextBox.Text);


And nothing happens. Did I forget something?

What I actually want is to add a value to the Collection every time a button is clicked.

Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: Adding values to AutoCompleteCustomSource doesn't work.

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 994
  • View blog
  • Posts: 2,382
  • Joined: 04-October 09

Re: Adding values to AutoCompleteCustomSource doesn't work.

Posted 15 May 2013 - 02:18 AM

I created a form with two textboxes and a button, with this code
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1 {
    public partial class Form1 : Form {
        AutoCompleteStringCollection source = null;
        public Form1() {
            InitializeComponent();
            textBox2.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            textBox2.AutoCompleteSource = AutoCompleteSource.CustomSource;
            source = new AutoCompleteStringCollection();
            source.Add("Albert");
            source.Add("Barney");
            source.Add("Clarence");
            source.Add("Betty");
            textBox2.AutoCompleteCustomSource = source;
        }

        private void button1_Click(object sender, EventArgs e) {
            textBox2.AutoCompleteCustomSource.Add(textBox1.Text.Trim());
        }
    }
}


And it works fine.
Was This Post Helpful? 0
  • +
  • -

#3 LaVeritas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 10-February 11

Re: Adding values to AutoCompleteCustomSource doesn't work.

Posted 15 May 2013 - 02:59 AM

View PostMomerath, on 15 May 2013 - 02:18 AM, said:

I created a form with two textboxes and a button, with this code
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1 {
    public partial class Form1 : Form {
        AutoCompleteStringCollection source = null;
        public Form1() {
            InitializeComponent();
            textBox2.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            textBox2.AutoCompleteSource = AutoCompleteSource.CustomSource;
            source = new AutoCompleteStringCollection();
            source.Add("Albert");
            source.Add("Barney");
            source.Add("Clarence");
            source.Add("Betty");
            textBox2.AutoCompleteCustomSource = source;
        }

        private void button1_Click(object sender, EventArgs e) {
            textBox2.AutoCompleteCustomSource.Add(textBox1.Text.Trim());
        }
    }
}


And it works fine.


I basically did the same. And yes I know it is working. While dubugging I saw this string being added to the collection. But I actually thought this would save the strings to the Collection even after exiting the application, which doesn't seem to be the case.

Did I get this wrong or does this save string to the collection forever?
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: Adding values to AutoCompleteCustomSource doesn't work.

Posted 15 May 2013 - 03:42 AM

Does the MSDN documentation state that it saves it?
The programming language is not psychic, it can not read your mind.
I have to tell it everything it has to do.
Was This Post Helpful? 4
  • +
  • -

#5 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3161
  • View blog
  • Posts: 9,541
  • Joined: 05-May 12

Re: Adding values to AutoCompleteCustomSource doesn't work.

Posted 15 May 2013 - 05:39 AM

I suspect that our OP has been spoiled by the "magic" behavior that most modern web browsers seem to have of an ever increasing autocomplete list, and not realizing that the "magic" that happens on the backend is that the browser is saving the new entries.
Was This Post Helpful? 0
  • +
  • -

#6 LaVeritas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 10-February 11

Re: Adding values to AutoCompleteCustomSource doesn't work.

Posted 15 May 2013 - 07:14 AM

View PostSkydiver, on 15 May 2013 - 05:39 AM, said:

I suspect that our OP has been spoiled by the "magic" behavior that most modern web browsers seem to have of an ever increasing autocomplete list, and not realizing that the "magic" that happens on the backend is that the browser is saving the new entries.


Exactly! Though I sense some sarcasm with the word "magic", this is exactly what I thought. Namely that once the string has been added to the collection it will persist forever like *.resx stuff does. Obviously I was wrong.

I got another solution for my problem:

To be presice the textbox belongs to a form the user has to fill in when he/she is making a db-entry. So why I needed the AutoComplete-collection is obvious too.

I solved this problem by populating the collection with strings (from db-entries), every time the form that contains the textbox is instatiated.

I simply tried to avoid using .resx

Thanks for your help!
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3161
  • View blog
  • Posts: 9,541
  • Joined: 05-May 12

Re: Adding values to AutoCompleteCustomSource doesn't work.

Posted 15 May 2013 - 04:28 PM

Actually, I was just making an allusion to the Arthur C. Clarke quote: "Any sufficiently advanced technology is indistinguishable from magic."
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1