How can I dynamically change auto complete entries in a C# combobox or textbox?

I had the same problem, and found an extremely simple workaround. As everybody else here, I couldn’t find any means to control de behaviour of the component, so I had to accept it.

The natural behaviour is: you can’t dynamically populate the list every time the user types into the text box. You have to populate it once, and then the AutoComplete mechanism takes control. The conclusion is: you should populate the AutoCompleteCustomSource with every possible entry in you database to make it work as we want.

Of course this is not viable if you have millions of records to populate the list. Performance issues in data transfer and the AutoComplete mechanism itself will not allow you to do that.

The compromise solution I found was: dynamically populate the AutoCompleteCustomSource every time that the Text length reaches exactly N chars (3 in my case). This worked because complexity was drastically reduced. The number of records that are fetched from the database that match these 3 initial chars was small enough to avoid any performance issues.

The major drawback is: users will not be presented the AutoComplete list until they type the N-th char. But it seems like users don’t really expect a meaningful AutoComplete list before 3 chars are typed.

Hope this helps.

Leave a Comment