关于combobox的SelectionChangeCommitted和SelectedIndexChanged事件 [英] About combobox's SelectionChangeCommitted and SelectedIndexChanged Events

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

问题描述

我在SelecttionChangeCommitted方法中使用组合框的选定索引获取用户选中的项目,但我喜欢SelecttionChangeCommitted方法将在方法SelectedIndexChanged之前执行,因此我得到了错误索引的错误结果过程。当绑定数据源和任何其他属性时,SelectedIndexChanged方法将执行几次,所以我只是不能使用SelectedIndexChanged方法,我应该处理它,你的想法是什么?谢谢。

i''m getting user''s selected item in SelecttionChangeCommitted method with the selected index of the combobox,but i fond the SelecttionChangeCommitted method will execute before the method SelectedIndexChanged,so i got a incorrect result course of the incorrect index.The SelectedIndexChanged method will execute a few times when binding the datasource and any property else,so i just cann''t use the SelectedIndexChanged method,and should i deal with it,what''s your idea?Thanks.

推荐答案





根据我对你的评论,我认为SelectedIndexChanged事件被多次触发绑定DataSource时。在这里,您始终可以应用以下条件来停止执行其余代码。

Hi,

As per my understanding from you above comments, I assume that the SelectedIndexChanged event is being fired multiple times while binding the DataSource. Here, you can always apply below condition to stop executing the rest of the code.
if (SelectedIndex > 0)





此外,设置ComboBox的属性--DropDownStyle = DropDownList,而不是任何其他东西。



使用SelectedIndexChanged和SelectionChangeCommited,下面这个链接将向你解释一个可能出现错误的场景。



这里 [ ^ ]



会有更多差异(在这里查看) [ ^ ],但请如果您有任何其他问题,请告诉我们。



圣诞快乐..!



问候,

Vamsi



Also, set the ComboBox''s property - DropDownStyle = DropDownList, instead of any other thing.

And for using SelectedIndexChanged vs SelectionChangeCommited, this below link will explain you one of the scenarios where you might get an error.

here[^]

There will be more differences (check here)[^], but please do let us know if you have any other concerns.

Merry Christmas..!

Regards,
Vamsi


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

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