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.
而且,如果我这样做,会不会对数据库造成太大的压力,并随着下一次提交而变得更糟?因为它似乎必须检查“home_team”和“away_team”的整个列,并在其中一个文本框中键入每个字母。
This is with Windows Forms.
这是Windows窗体。
1 个解决方案
#1
4
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 AutoComplete
propreties to your Textbox.
一旦您拥有了所有字段,只需将它们放入列表中,文本框中就会有自动完成的前缀。
Set the Auto Complete Mode
and the Auto Complete Source
and you're done!
设置自动完成模式和自动完成源代码,您就完成了!
Check this example out, it's very simple!
看看这个例子,它非常简单!
在c#中自动完成文本框
#1
4
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 AutoComplete
propreties to your Textbox.
一旦您拥有了所有字段,只需将它们放入列表中,文本框中就会有自动完成的前缀。
Set the Auto Complete Mode
and the Auto Complete Source
and you're done!
设置自动完成模式和自动完成源代码,您就完成了!
Check this example out, it's very simple!
看看这个例子,它非常简单!
在c#中自动完成文本框