为什么将SelectedValueChanged提高2倍? [英] Why is SelectedValueChanged raised for 2 times?

查看:83
本文介绍了为什么将SelectedValueChanged提高2倍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不明白它是怎么发生的?我在其项目"列表中只有一个2个值的组合框.我有一个与组合框的SelectedValueChanged事件关联的方法,但是我发现只要我通过仅从组合框的2个值中选择1个来更改选定的值,它就可以提高2倍.在引发事件并调用与之关联的相应方法时,其值不变(我选择的值).更改后该值不会更改,但是SelectedValueChanged会升高2倍,一次是在我完成更改其值时,另一次是在?我的组合框只有2个值可以选择,如果SelectedValueChanged连续提高2次,则它应该返回其值之前(例如,其值为0和1,首先是选定的值是0,是事件的2倍后)提出它应该是0而不是1),但事实并非如此.听不懂您能否给我一些关于如何以及何时可行的想法.

另外,实际上,我还有其他组合框,其SelectedValueChanged事件与同一方法相关联.当更改这些组合框的值时,该事件通常仅触发一次,但是它们与我前面提到的奇数组合框有何不同?我的奇数组合框没有任何数据绑定或任何可以更改其值的关联,除非从下拉列表中选择一个!
非常感谢!

解决方案

哇!我自信地说,我自己找到了自己的问题的答案.就是这样.
我将一个方法与奇数" comboBox的SelectedValueChanged事件关联了两次!!!这就是为什么在事件触发时,该方法将被调用两次的原因.如果您重复执行三次,四次或更多次,则将恰好在该时间调用.因此,如果您遇到相同的问题,请重新检查一下是否将该方法与事件关联了一次,当然,可能还有其他原因. 哈哈,我明白了!
多亏了我自己! 4862-9c5d-75cf85acd8dc>此线程 [ 解决方案

Wow! I confidently say that I have found the answer to my own question by myself. That is simply.
I associated a method to the "odd" comboBox''s SelectedValueChanged event twice!!! That''s why when the event fires, the method will be called twice. If you do the same with three, four or more times it will be call exactly for such time. So if you have the same problem, recheck to see if you have associated the method more one time with the event, of course, there may be other causes.
Haha, I got it!
Thanks to myself!


Have a look at this thread[^]. It may help you out.


I know you''ve solved this now but here''s a hint for the future. Unless you dynamically create a control, it''s well recommended to always use the designer to add event handlers. This way you will not accidentally add it twice. You may not be able to follow this rule everywhere, so if there are scenarios where you absolutely must add it in user written code, then make sure you do it all in one place, so it''s easier to debug.


这篇关于为什么将SelectedValueChanged提高2倍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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