textppres后,keypres不会触发 [英] keypres doesnt fire after textchanged
本文介绍了textppres后,keypres不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我有一个文本框,其中有两个事件,第一个是txtsearch_TextChanged,它自动完成另一个是txtsearch_KeyPress,其中传递数据点击进入txtsearch_TextChanged stop txtsearch_KeyPress解雇
怎么能我让他们两个一个接一个地工作,然后第一个文本更改然后按键事件没有问题?
编辑:复制评论:
hi everybody i have atextbox which have two events first txtsearch_TextChanged which fire to autocomplete the other is txtsearch_KeyPress which pass data in click enter txtsearch_TextChanged stop txtsearch_KeyPress firing
how can i make both of them work one after the other textchanged first then keypress event without problem ?
Copied from comments:
private void txtsearch_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
string Str = txtsearch.Text.Trim();
double Num;
bool isNum = double.TryParse(Str, out Num);
if (isNum)
{
// search by barcode
prd = new BLL();
DataTable dta = new DataTable();
dta = prd.findbybarcode(txtsearch.Text);
txtid.DataBindings.Clear();
txtid.DataBindings.Add("text", dta, "ID");
txtproductname.DataBindings.Clear();
txtproductname.DataBindings.Add("text", dta, "proname");
txtprice.DataBindings.Clear();
txtprice.DataBindings.Add("text", dta, "price");
txtunit.DataBindings.Clear();
txtunit.DataBindings.Add("text", dta, "Unit");
txtcount.Focus();
}
}
}
private void txtsearch_TextChanged(object sender, EventArgs e)
{
txtsearch.AutoCompleteMode = AutoCompleteMode.Suggest;
txtsearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
AutoCompleteStringCollection DataCollection = new AutoCompleteStringCollection();
getData(DataCollection);
txtsearch.AutoCompleteCustomSource = DataCollection;
}
推荐答案
我已经尝试过您的代码。
据我所知,输入密钥不再处理txtsearch.AutoCompleteMode = AutoCompleteMode.Suggest;
已经运行。哪种有意义 - 输入键将用于从可能的自动完成条目列表中选择。
因为您没有过滤自动完成集合,为什么没有在Form_Load
或txtsearch_Enter
事件之一中设置? Enter键仍然不起作用,但文本框的行为更好。
我不知道key_leave事件是什么。如果你的意思是txtSearch_Leave
事件,它对你的自动完成没有帮助。
如果你真的想捕获然后输入密钥然后尝试使用txtsearch_KeyUp
事件
我还尝试了事件的顺序通过播放我连接它们的命令来解雇。它似乎没有相关性 - 例如,连接事件的顺序
I've experimented with your code.
As far as I can tell the Enter key is no longer handled oncetxtsearch.AutoCompleteMode = AutoCompleteMode.Suggest;
has been run. Which sort of makes sense - the Enter key would be used to pick from the list of possible auto-complete entries.
As you are not filtering the autocomplete collection, why not set that up in one of theForm_Load
ortxtsearch_Enter
events? The Enter key will still not work, but the behaviour of the text box is better.
I have no idea what the key_leave event is. If you meant thetxtSearch_Leave
event it won't help with your autocomplete.
If you really want to capture the Enter key then try using thetxtsearch_KeyUp
event instead
I also experimented with the order of the events that were fired by playing about with the order that I wired them up. It doesn't appear to be relevant - for example this order of wiring up the events
this.txtsearch.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txtsearch_KeyUp);
this.txtsearch.TextChanged += new System.EventHandler(this.txtSearch_TextChanged);
this.txtsearch.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtSearch_KeyPress);
仍然导致事件的顺序
key pressed
text changed
key up
(正如我尝试过的其他订单组合一样)
(As did the other combinations of order that I tried)
这篇关于textppres后,keypres不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文