我的问题类似于这样: 如何防止ListBox.SelectedIndexChanged事件? ,但我想问一个不同的方式。
有没有一种简单的方法来确定'SelectedIndexChanged'是否来自用户,而不是通过代码启动(例如ListBox.SelectedIndex = x)?
My question is similar to this: How to prevent ListBox.SelectedIndexChanged event?, but I want to ask it a different way.
Is there a simple way to determine if the 'SelectedIndexChanged' is coming from the user as opposed to initiated through code (e.g. ListBox.SelectedIndex = x)?
最满意答案
据我所知,不,没有简单的内置方法。 我已经能够做的最好的就是在代码改变之前设置一个标志,然后让事件处理程序重置标志并返回。
我想你可以开始检查调用堆栈,看看它是否在你自己的代码的某个地方发起,但我不确定这个工作值多少钱。
As far as I know, no, there's no simple way built-in. The best I've been able to do is set a flag just before changing it in code and then letting the event handler reset the flag and return.
I suppose you could start examining the call stack and see if it's originating somewhere in your own code or not, but I'm not sure how much it's worth the effort.
更多推荐
发布评论