Search code examples
c#winformsautocompletetextboxlayered

Autocomplete textbox in layered architecture


I want to create an autocomplete textbox with my database.

I'm programming my application in a layered architecture (models, DAL, BLL, Presentation).

I've already made a method with an arraylist that reads and returns my select command in the database, which is filling (I've tested on a combobox).

But when I try to insert in the the textbox, nothing happens... it doesn't show the suggestion.

I looked for something in the forum but I just found examples with one layer and, since I'm developing in layers I cannot increment the property AutoCompleteStringCollection in my DAL to be filled by my select command.

If anyone has any idea how to solve this problem, please explain to me!

Additional information: I'm using winForm with C# and SQL Server.


Solution

  • I think you want to say that "But when i try to insert in the textbox, nothing happens... it doesn't show the sugestion." well i cannot just code all layers here but can suggest in your DAL create a method which returns List and then on your form page provide code like this

     txtName.AutoCompleteMode = AutoCompleteMode.Suggest;
     txtName.AutoCompleteSource = AutoCompleteSource.CustomSource;
     var autoCompleteCollection = new AutoCompleteStringCollection();
     autoCompleteCollection.AddRange(DAL.GetMethod().ToArray());
     textbox.AutoCompleteCustomSource = autoCompleteCollection;