textppres后,keypres不会触发

编程入门 行业动态 更新时间:2024-10-25 14:25:00
本文介绍了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 once txtsearch.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 the Form_Load or txtsearch_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 the txtSearch_Leave event it won't help with your autocomplete. If you really want to capture the Enter key then try using the txtsearch_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不会触发

本文发布于:2023-11-27 01:39:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636050.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:textppres   keypres

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!