停止comboBox的selectedIndexChanged事件触发表单加载 [英] Stop comboBox's selectedIndexChanged event from firing when the form loads

查看:168
本文介绍了停止comboBox的selectedIndexChanged事件触发表单加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 ComboBox 的表单,提供了一个下拉列表。在comboBox的 SelectedIndexChanged事件中,我运行一些代码,但我不希望该代码在表单加载时运行。不幸的是,当我加载窗体(在组合框中进行选择之前),组合框的 SelectedIndexChanged 触发(我想当组合框是数据绑定)。有没有办法避免这种行为?

I have a form with a ComboBox that provides a dropdownlist. On the comboBox's SelectedIndexChanged event, am running some code, but I don't want that code to run when the form loads. Unfortunately, when I load the form (before I make a selection in the combobox), SelectedIndexChanged of the combobox fires (I think when the combobox is databinding). Is there a way of avoiding such behaviour?

推荐答案

如果您只想在用户更改组合中的选定项目时做出反应框,那么最好订阅 SelectionChangeCommitted

If you want to react only when the user change the selected item in the combo box, then it is better to subscribe to SelectionChangeCommitted.

这篇关于停止comboBox的selectedIndexChanged事件触发表单加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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