[Solved] Setting the focus or cursor in a Dialog
[Solved] Setting the focus or cursor in a Dialog
I have a dialog in a spreadsheet document with various Check Boxes, Radio and Control Buttons, and Text Boxes. Based on which button gets pushed or which checkbox gets checked I'd like the focus / cursor (I'm not sure what it's called) to be placed on / in one of the Text Boxes. As a user, after clicking a button or checkbox, I can hit the Tab key until the appropriate Text Box gets focus, but I'd like to do that programatically through On-action macros assigned to the buttons and checkboxes. How do I do this?
Last edited by Alex6361 on Tue Jun 16, 2015 9:06 am, edited 3 times in total.
LibreOffice Version: 7.4.7.2
Debian Linux 12 & Windows 11
Debian Linux 12 & Windows 11
Re: Setting the focus or cursor in a Dialog
Similar topics:
viewtopic.php?f=45&t=20279
viewtopic.php?f=45&t=43376
viewtopic.php?f=20&t=26957
from the another (old) Forum - it is rarely available:
http://www.oooforum.org/forum/viewtopic.phtml?t=74510
viewtopic.php?f=45&t=20279
viewtopic.php?f=45&t=43376
viewtopic.php?f=20&t=26957
from the another (old) Forum - it is rarely available:
http://www.oooforum.org/forum/viewtopic.phtml?t=74510
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Setting the focus or cursor in a Dialog
Thanks again, Tibor, for trying to help me over another impasse! As it turns out, the links you suggested were for cases when the control was on a DrawPage or database form, and the case I had is for controls on a Dialog accessed by a macro from a spreadsheet document. I finally stumbled onto the solution, and it is just what I would have wanted it to be, but not documented in a straightforward way. In fact, the API documentation I'm using gave me the impression that the method was only valid for windows, and not things on them. Anyway, the following code shows how it's done.
Code: Select all
Sub SetTheFocus()
Dim oMyDialog as Object
Dim sDialogName as String
Dim sControlName as String
sDialogName = "<name of your dialog goes here>"
sControlName = "<name of the control on your dialog goes here>"
'the following has probably already been done before you need to set focus on anything:
DialogLibraries.LoadLibrary("Standard")
if IsNull(oMyDialog) then
oMyDialog = CreateUnoDialog (DialogLibraries.getByName("Standard").getByName(sDialogName))
end if
'the following line is all it takes once you have an object handle for the dialog
oMyDialog.GetControl(sControlName).setFocus()
'the next time the dialog is presented the focus / cursor should be on / in sControlName
oMyDialog.execute
End Sub
LibreOffice Version: 7.4.7.2
Debian Linux 12 & Windows 11
Debian Linux 12 & Windows 11