views:

33

answers:

1

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?

A: 

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.

WOPR
That's a great idea, thanks
Sisiutl