是否有可能触发组合框的SelectedIndex更改事件,即使旧的和新的索引是一样的吗?组合、有可能、索引、事件

2023-09-04 13:12:06 作者:烟云似雪

我有一种情况是,我需要火的winform的COMBOX的的SelectedIndexChanged 事件,即使旧的和新的指标是一样的。我不能使用 SelectionChangeCommited ,因为数值被设置编程..它不会被解雇。是不是任何机会给力的SelectedIndexChanged火,即使旧的和相同的指数是一样的吗?

I have a scenario is which I need to fire the SelectedIndexChanged event of a winform's combox even when the old and new index is same.. I can not use SelectionChangeCommited because the values are being set programmatically .. and it wont get fired. Is it by any chance to force 'SelectedIndexChanged' to fire even when old and same index are same?

推荐答案

没有prevents你直接调用事件处理程序:

Nothing prevents you from calling event handler directly:

comboBox1_SelectedIndexChanged(comboBox1, new EventArgs()); // or (null, null)

atomaras 的解决方案是一个更好的(更好)的方式来做到这一点。

But solution of atomaras is a better (nicer) way to do it.

我自己不喜欢使用标准组件更不太严重的软件。相反,我继承所有的标准组件,从一开始,并尽快增加功能他们,因为我需要它,而不需要在现有的形式改变什么。

I myself dislike to use standard components in more-less serious software. Instead I subclass all standard components from very beginning and adding functionality to them as soon as I need it without needs to change anything in the existing forms.

在这种情况下,我想补充一个公共事件立管 OnSelectedIndexChanged 来执行事件(运行事件处理中code的编程的)

In this case I'd add a public event riser OnSelectedIndexChanged to execute event (to run code inside event handler programmatically).