c#.net中的动态自动完成文本框 [英] Dynamic auto complete text box in c#.net

查看:149
本文介绍了c#.net中的动态自动完成文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.net中的自动完成文本框属性在编码阶段提供了自定义源,但它必须在运行时在源中保存新的。我找到代码但新的代码保存到应用程序打开之前。然后我们关闭并再次打开它不会显示新的。

Auto complete textbox property in .net has the custom source was given in coding phase but it had to save new ones aromatically in the source at run time .I find the code but the new ones are saved until the app is open.and then we close and open it again it will not showing the new ones.

推荐答案

属性你必须设置到文本框:



AutoCompleteMode:建议追加

AuoCompleteSource:CustomSource



这些属性必须设置为文本框,为这你要设置AutoCompleteMode的文本框。

然后只会执行代码。





事件:此代码应在Page_Load中编写事件





的SqlCommand CMD =新的SqlCommand( 从databasetable选择姓名,CON); <无线电通信/>
SqlDataReader dr = cmd.ExecuteReader();

AutoCompleteStringCollection col = new Aut oCompleteStringCollection();

while(dr.Read())

{

col.Add(dr.GetString(0)); < br $>
}



textBox1.AutoCompleteCustomSource = col;



我希望这段代码将帮助您。



以及其他供您参考的链接



http://www.c-sharpcorner.com/uploadfile/tajwerj/dynamically-fill-autocomplete-文本框从 - datagridview的/ [ ^ ]
Properties those you have to set to the textbox :

AutoCompleteMode : Suggest Append
AuoCompleteSource : CustomSource

These properties must set to the textbox that to which textbox you want to set the AutoCompleteMode.
Then only the code will be performs.


Event: This code should write in Page_Load event.


SqlCommand cmd = new SqlCommand("select name from databasetable", con);
SqlDataReader dr = cmd.ExecuteReader();
AutoCompleteStringCollection col = new AutoCompleteStringCollection();
while (dr.Read())
{
col.Add(dr.GetString(0));
}

textBox1.AutoCompleteCustomSource = col;

I hope this code will help you.

and also other link for your reference

http://www.c-sharpcorner.com/uploadfile/tajwerj/dynamically-fill-autocomplete-textbox-from-datagridview/[^]


这篇关于c#.net中的动态自动完成文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆