I have placed a ListBox Control on a Calc Sheet and assigned a Basic Macro to the control’s ‘Changed’ event. The last thing the macro does is place the cursor on a desired cell on the sheet using:
dispatcher.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:GoToCell", "", 0, args())
Everything works as desired except: After the macro completes execution, the ListBox sometimes retains focus, but sometimes it does not. By ‘retains focus’ I mean that the ListBox displays the dotted-line around the box (indicating focus) and the selected item shown in the box is highlighted with a blue background. Since the Control still has focus, pressing the up/down arrow keys causes the previous/next item in the list to be selected and triggers the ‘Changed’ event again, and the ListBox retains focus. The Control’s
TabStop property is set to ‘No’. So when the ListBox has focus, pressing the Tab key does not remove focus from the Control.
After macro completion, if I manually use the mouse to select any cell on the sheet, the ListBox immediately loses focus, the dotted lines in the Control disappear, the background of the selected item reverts to the white background, and pressing the arrow keys moves the ‘cursor’ to the next cell above or below the selected cell.
Behavior is the same regardless of if I select a ListBox item using the mouse to pull-down and click a selection, or if I use the arrow keys to simply move up or down in the selection list. I have tried using
ThisComponent.CurrentController.Select(cell) in combintion with the above ‘dispatch’ command and separately with no change in behavior: Sometimes the ListBox retains focus when the macro completes, and sometimes it does not.
Can anyone suggest a way for me to dependably remove focus from the ListBox Control after it is used to select an item?
I have been unable to identify a specific sequence of actions or macro code that will dependably predict whether the control will retain focus or not.