触发组合框selectedIndexedchanged事件的问题 [英] problem on firing combobox selectedIndexedchanged event

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

问题描述

你好朋友
我正在使用C#开发Windows应用程序.我有两个用于国家的组合框1.combox1,用于州的2.combobox2
在表单数据(国家名称)的page_load事件中,已将其绑定到SQL Server的combobox(combobox1)中.然后我通过使用combobox1_selectedindexchanged事件基于第一个combobox选择值从sql向comobobox(combobox2)添加另一个数据(状态名称).但是问题是在page_load事件本身发生了combobox1_selectedindexchanged事件.但我需要的是从第一个combobox1中选择值后添加了combobox2值.

Hi friends
I am developing windows application using c#. I have a two comboboxes 1.combox1 for country, 2.combobox2 for state
In the page_load event of form data(country name) has been boundto combobox(combobox1) from sql server. then i add another data(state name) to comobobox(combobox2)from sql based on the first combobox selected value by using combobox1_selectedindexchanged event.but the problem is combobox1_selectedindexchanged event occurs at the page_load event itself. but what i need is combobox2 value is added after selecting the value from first combobox1. what would be problem on my process.

推荐答案

以这种方式发生组合框selectedindex更改事件是正常现象.选定索引的可能性是-1,您只需要检查该值就可以,在这种情况下不执行任何操作,也可以清除第二个组合,因为在第一个组合中没有选择任何内容.
It is normal behaviour for the combobox selectedindex changed event to occur this way. Chances are the selected index is -1 and you just have to check for that value and do nothing in that case or clear the second combo because nothing is selected in the first combo.


这种问题可以使用SelectionChangeCommitted事件.
To avoid this kind of problems you can use SelectionChangeCommitted event.


这篇关于触发组合框selectedIndexedchanged事件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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