如何在TextBoxes中实现AutoComplete n C# [英] How to implement AutoComplete in TextBoxes n C#
本文介绍了如何在TextBoxes中实现AutoComplete n C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框和一个数据库。每次用户在文本框中键入内容时,从数据库中加载带有字符串匹配文本框字符串的数据。
现在,如何在搜索引擎中显示的自动完成模式下显示此数据?
我正在使用的数据库是SQL。
I have a textbox and a database.Everytime the user types something in the textbox,data with string matching textbox's string is loaded from the database.
Now,how can i show this data in the AutoComplete Mode as it appears in Search Engines?
The database i'm using is SQL.
推荐答案
这种方式...
This way...
private void Form1_Load(object sender, EventArgs e)
{
// declare custom source.
var source = new AutoCompleteStringCollection();
// fetch record from database
datatable dt = getdatafromsql("select name from tbl");
// fill database records to custome sorurce
for (i=0;i<dt.rows.count;i++)>
{
source.Add(dt.rows[i][0].tostring(););
}
// Create and initialize the text box.
var textBox = new TextBox
{
AutoCompleteCustomSource = source,
AutoCompleteMode =
AutoCompleteMode.SuggestAppend,
AutoCompleteSource =
AutoCompleteSource.CustomSource,
Location = new Point(20, 20),
Width = ClientRectangle.Width - 40,
Visible = true
};
// Add the text box to the form.
Controls.Add(textBox);
}
快乐编码!
:)
Happy Coding!
:)
试试这个
Try this
public void AutoComplete()
{
AutoCompleteStringCollection AutoItem = new AutoCompleteStringCollection();
foreach (DataRow rw in Dt.rows)
{
AutoItem.Add(Rw["columnname"].ToString());
}
texbox.AutoCompleteMode = AutoCompleteMode.Suggest;
texbox.AutoCompleteSource = AutoCompleteSource.CustomSource;
texbox.AutoCompleteCustomSource = AutoItem;
}
http://www.aspdotnet-suresh.com/2012/08/using-jquery-autocomplete-with-aspnet.html [ ^ ]
查看此链接..
http://www.aspdotnet-suresh.com/2012/03 /jquery-ui-autocomplete-textbox-with.html [ ^ ]
这篇关于如何在TextBoxes中实现AutoComplete n C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文