So here’s an example of what I’m trying to do. Lets assume I’m making a soccer game submitting program and I have a few fields that I’m supposed to fill, 2 of which I want autocomplete on. One textBox for the Home Team and one textBox for the Away Team.
Here is an simplified example of what the database table would look like:
-----------------------------
| home_team | away_team |
-----------------------------
| Chelsea FC | Arsenal |
| Liverpool | Norwich FC |
| Man. City | Everton |
| Tottenham | Stoke City |
I want the program to load suggestions or results checking every team in the table when I type something in any of the two textBoxes. This is to make typing the correct team names easier and faster based on former submissions.
How would this be done?
Also, if I do this, would it be too much of a strain on the database and getting worse with every next submission? Because it seems as though it would have to check the whole of the “home_team” and “away_team” columns with every letter I type into one of the textBoxes.
This is with Windows Forms.
You’ll definitly want to get all of your Data and Fields when the Form is loaded. Executing a request everytime you type a letter is a bad idea.
Once you have all of your fields, simply put them in a list and there are
AutoCompletepropreties to your Textbox.Set the
Auto Complete Modeand theAuto Complete Sourceand you’re done!Check this example out, it’s very simple!
Auto Complete TextBox in C#