当表单加载时停止组合框的 selectedIndexChanged 事件 [英] Stop comboBox's selectedIndexChanged event from firing when the form loads

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

问题描述

我有一个带有 ComboBox 的表单,它提供了一个下拉列表.在组合框的 SelectedIndexChanged 事件 上,正在运行一些代码,但我不希望该代码在表单加载时运行.不幸的是,当我加载表单时(在我在组合框中进行选择之前),组合框的 SelectedIndexChanged 会触发(我认为当组合框是 databinding 时).有没有办法避免这种行为?

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.

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

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