Comobox事件SelectedValueChanged [英] Comobox event SelectedValueChanged

查看:136
本文介绍了Comobox事件SelectedValueChanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的问题可能有人问我之前,但我找不到it.Let说我有datatable,有一些数据从数据库,我想绑定到一个组合框我使用标准代码这样



i have simple question may be someone asked it before me but i could not find it.Let say i have datatable that has some data from the database and i want to bind it to a combobox i use standart code like this

 comboBox1.BeginUpdate( );
 comboBox1.ValueMember = "id";
 comboBox1.DisplayMember = "name";
 comboBox1.DataSource = dt;
 comboBox1.EndUpdate( );

问题是在绑定事件期间 SelectedValueChanged

The problem is during this binding the event SelectedValueChanged is fired.The problem is that rebind combo several times when outher values change and every time i must do sometihn like this

 comboBox1.SelectedIndexChanged -= new System.EventHandler( this.comboBox1_SelectedValueChanged );

我的问题是有一个更聪明的方式来跳过事件,当我来自数据绑定,而不是从用户输入。问题是,我想做一些如何globaly在我的控制继承combobox,而不是每次在每个从
最好的问候,
Iordand

my question is there a smarter way to skip the event when i comes from databinding not from user input.The problem is that i want to do it some how globaly in my control that inherits combobox and not to do it everytime in every from Best Regards,
Iordand

推荐答案

尝试使用 SelectionChangeCommitted 事件。

从MSDN文档:


SelectionChangeCommitted 仅在用户更改
组合框选择时引发。 不要使用 SelectedIndexChanged
SelectedValueChanged 捕获用户更改,因为这些事件是
当选择以编程方式更改时也会引发。

SelectionChangeCommitted is raised only when the user changes the combo box selection. Do not use SelectedIndexChanged or SelectedValueChanged to capture user changes, because those events are also raised when the selection changes programmatically.

这篇关于Comobox事件SelectedValueChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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