Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
944
Preventing Event Handlers from firing
posted

Is there a way to prevent an Event Handler from firing on the WinCombo?

For example, I want the control to fire the ValueChanges event handler if the user changes the value, however I dont want the event handler to fire if the value is change due to data in the underlying data source changes.

The reason I need to do this is that I have two combo's on the form. Combo1 and Combo2. The value set in Combo2 depend on the option selected in Combo1. Combo1 retrieves previously saved values for Combo2 from the Db. 

If a user manually changes the value of Combo2, then my event handler goes off and does some processing (such as calculations based on Combo2's value).

If Combo1 is changed, when Combo2 reloads with it's new value, the event handlers are again firing. However the ValueChanged event handler fires twice. Once for removing the set value in Combo2, and then again a second time when the new value is set.

When this fires the first time, the program craps out because there is no set value. It then does not continue to fire for the second time when a value have been set.

How can I get around this?

Cheers

 

  • 469350
    Verified Answer
    Offline posted

    Hi Jason,

        You can use the EventManager to enable/disable events in the control. So if you know your code is about to cause an event, you can disable the event, run the code, and then re-enable the event.

        You could also just unhook and then re-hook the event, too.  But the EventManager is generally easier and safer to use. 


                this.ultraCombo1.EventManager.SetEnabled(ComboEventIds.ValueChanged, false);
                try
                {
                    // My code here
                }
                finally
                {
                    this.ultraCombo1.EventManager.SetEnabled(ComboEventIds.ValueChanged, true);
                }