级联组合框中的事件

发布于 2024-09-12 14:05:37 字数 459 浏览 1 评论 0原文

我创建了一个 WinForms 用户控件,它是一组五个级联组合框 - 用户从顶部组合中选择一些内容,然后填充并启用第二个组合,依此类推。如果新启用的组合中只有一个选项,我会自动选择它,从而导致其下面的选项变为活动状态。因此,单个用户操作可以通过几个附加组合产生连锁反应。

我提出一个特定于每个组合框的事件。我还想在任何事情发生变化时提出最终事件。例如,用户从顶部组合中选择一个选项。这将引发 Combo1Changed 事件。如果这会自动导致在第二个组合中进行选择,那么我还会引发 Combo2Changed 事件。当这一切完成后,我想引发一个 SomethingChanged 事件。

现在,每次组合更改时,我都会引发 ComboXChanged 和 SomethingChanged 事件。但由于单个选择可以级联所有五个组合,因此可能会引发数十个事件。

我不知道如何确定级联何时完成,以便我可以仅触发事件一次。是否有一个聪明的技巧或模式来编码这种事情?

I have created a WinForms user control that is a set of five cascading combo boxes - the user selects something from the top combo which then populates and enables the second combo, and so on. If there is only one option in the newly enabled combo I automatically select it, causing the one below it to become active. Consequently a single user action can ripple down through several additional combos.

I raise an event specific to each combo box. I also want to raise a final event any time anything changes. For example, the user selects an option from the top combo. This raises the Combo1Changed event. If this automatically causes a selection in the second combo then I would also raise a Combo2Changed event. When it's all done I want to raise a single SomethingChanged event.

Right now I raise the ComboXChanged and the SomethingChanged events every time a combo changes. But since a single selection can cascade down all five combos it can potentially cause dozens of events to be raised.

I can't figure out how to determine when the cascading has finished, so that I can fire the events just once. Is there a clever trick or pattern for coding this kind of thing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏九 2024-09-19 14:05:37

您可以通过使用一个类来解决此问题,所有组合框都将其选择更改事件传递给该类,并引发一个封装其他事件的单个 Somethingchanged 事件。

话虽如此,我会考虑重新设计该用户界面。您是否考虑过用树视图替换四个甚至所有下拉列表?这对于用户来说会更容易导航。

You could solve this by having a class which all the combo boxes pass their selection changed events to and which raises a single somethingchanged event which encapsulates the other events.

Having said that, I'd look at redesigning that ui. Have you considered replacing four or even all of those drop down lists with a tree view? That would be much easier for the user to navigate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文