Conditional logic in FocusLost depending on object receiving ficus

Let’s say I would like to run some conditional logic in the FocusLost event of a DesktopComboBox, but it should only run if the object that receives the focus thereafter is not a certain object. How could I achieve this?

With a Boolean and a Timer of ~1 second. After leaving the DesktopComboBox set the Boolean to True then run the Timer.

If the certain object gets the Focus, set the Boolean to false immediately. In the Timer check the Boolean and, if True, run your Method. Hopefully the Method will no longer run since the Focus is on the certain object.

1 Like

Thanks for that. I see one problem with this. What if a button is clicked before timer action is executed and that button requires that the timer action is complete?

Then make the timer shorter. If you make it 1/10 of a second, there’s no way a user will have time to click the button.

But really, you could just set a property in the LostFocus event indicating which control had focus and then check that property in the GotFocus event. That would probably get you what you want.