I have some logic inside a DesktopComboBox (that resides in a Container) FocusLost event to check for a flag value. If true, I want the entire Container containing the ComboBox to close. I tried using Self.Close inside the FocusLost event but this silently closes the app aswell without raising any exceptions.
Any ideas why this is happening?
Some background: when the container is instantiated, it is embedded to the window called from a ListBox (Me.Window) event and a reference to the Container is held in a property of the window.
That sounds like your app is crashing. You might want to use Timer.CallLater to call a method that closes the container just to get it out of that event. Key events are a notoriously bad place for anything like this.
I had a thought after looking at the stack and order of execution.
When mouse is clicked elsewhere in ListBox, it checks to see if any container instance exists, and if so, it closes it before recreating a new one at new cell position.
It looks like when running the Self.Close command in the MouseDown event of the ListBox, before it destroys the container instance, it jumps to the LostFocus event of the ComboBox in the Container (as that had focus before MouseDown). In the LostFocus event, I also do another logic check for a flag (explained above), and close container if true.
is the issue that the ComboBox has focus before Self.Close is called from the MouseDown event of ListBox or from the LostFocus of the ComboBox itself before attempting to close the container?
Or is it because Self.Close is essentially called twice: once in MouseDown and again when it jumps to LostFocus event?
I think it’s number 2 above. I can remove Self.Close from LoseFocus of the ComboBox. However, when clicking elsewhere apart from the ListBox, the container does not close. How can I make it so that the container closes regardless of whether I click on a TextField, on the Window itself etc?
The only way I can think of doing this is closing the container when any other control in the window has focus, but this doesn’t seem like a proper way of doing it just to avoid using the LostFocus event of the ComboBox itself.