简体   繁体   中英

how to set database as the source of auto-complete in C#

我有一个文本框。现在我想对此文本框使用自动完成选项,但我想使用自动完成源是我的数据库。也就是说,我有一个包含1000个单词的数据库。所以每当用户输入一个文本到文本框中,它提示数据库中的一个单词。因此,我如何使用数据库作为文本框自动完成的来源?

You can use the AutoCompleteStringCollection and populate it with strings from your database:

var autoCompleteData = new AutoCompleteStringCollection();
autoCompleteData.add("SomeString1"); // Can be strings retrieved from database
autoCompleteData.add("SomeString2"); // Can be strings retrieved from database

textBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
textBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox.AutoCompleteCustomSource = autoCompleteData;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM