[Solved] Setting focus in table grid with a macro
[Solved] Setting focus in table grid with a macro
I have a form with a table (grid) control. How can I move the input focus to a particular column in the table from within a macro? Thanks!
Last edited by void64 on Sat Jan 30, 2010 10:00 pm, edited 1 time in total.
Dream of Space? Help make it Real.
http://www.open-aerospace.org/
http://www.open-aerospace.org/
Re: Setting focus in table grid with a macro
The table (grid) control bundles other controls in columns. Focus a control within the grid.
Edit: I'm wrong. It is not that simple. |
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Setting focus in table grid with a macro
Can you be a little more specific? I'm still not that well-versed in the ooBasic object model. I tried using the code snippet shown here as an example, but I'm having difficulties because my table is in a sub-sub-form.Villeroy wrote:The table (grid) control bundles other controls in columns. Focus a control within the grid.
I want to place the focus on a specific column (named "Cause") in the very lowest TableControl.
Thanks for the help.
Dream of Space? Help make it Real.
http://www.open-aerospace.org/
http://www.open-aerospace.org/
Re: Setting focus in table grid with a macro
While in edit mode, select a column header of the grid control and call the properties dialog. Watch the dialog title and the properties. Right-click the column and see the control types to replace the current column control.
A table control is not a control in its own right. It can not be bound. Most event routines do not work. It consists of other controls, one per column, showing one instance of the same control bundle per row.
A table control is not a control in its own right. It can not be bound. Most event routines do not work. It consists of other controls, one per column, showing one instance of the same control bundle per row.
Edit: Anyhow, I can't select any of them by macro. |
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Setting focus in table grid with a macro
Looks like there is no method to set the focus specifically to a random column ... bummer. As an alternative, I figured if I can send a "tab" key-stroke than this would allow me to walk my way to the control I want. I used the macro recorder to capture a code snippet that does just that (send a tab) and got:
But when executing it nothing seems to happen - where did I go wrong?
Code: Select all
sub Tab
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = CHR$(9)
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
end sub
Dream of Space? Help make it Real.
http://www.open-aerospace.org/
http://www.open-aerospace.org/
Re: Setting focus in table grid with a macro
Thanks, that was helpful! I tried using this code snippet to set the focus:
Code: Select all
oController = ThisComponent.CurrentController
oForm = ThisComponent.drawpage.forms.GetByName("FailureModes")
cControl = oForm.GetByName("CauseName")
oControlView = oController.GetControl(cControl)
oControlView.SetFocus 'sets the focus
Dream of Space? Help make it Real.
http://www.open-aerospace.org/
http://www.open-aerospace.org/
Re: Setting focus in table grid with a macro
It's all in Romke's first link: http://user.services.openoffice.org/en/ ... ol#p109535 (last snippet).void64 wrote:Can you tell me how to modify this code so I can access the table in the sub-form (rather than the main form)?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Setting focus in table grid with a macro
Almost, except the "GetControl" method returns an empty object when used on the oField object, so I get an error when I try to use the "SetFocus" method. I can xray the oField object just fine though, and it is the correct object that I'm trying to set the focus to ...?
Code: Select all
oDoc = thiscomponent.drawpage.forms
oForm = oDoc.getbyname("Steps")
oSubForm = oForm.getbyname("CompList")
oSubSubForm = oSubForm.getbyname("FailureModes")
oSubSubFormGrid = oSubSubForm.getbyname("TableControl")
oField = oSubSubFormGrid.GetByName("CauseName")
'xray oField
oControlView = ThisComponent.CurrentController.GetControl(oField) 'THIS LINE RETURNS EMPTY
oControlView.SetFocus
Dream of Space? Help make it Real.
http://www.open-aerospace.org/
http://www.open-aerospace.org/
Re: Setting focus in table grid with a macro
Hello
You have to modify the code to your needs. you can not complete copy the code.
Maybe this link is better.
Romke
You have to modify the code to your needs. you can not complete copy the code.
Maybe this link is better.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Re: Setting focus in table grid with a macro
Hi Romke, thank you for trying to help! I did write the last code snippet I posted myself, using the links you provided as an example. The problem is not finding the object, but the fact that there seems to be no control associated with elements that are embedded in a table grid. At least that's my guess why "ThisComponent.CurrentController.GetControl(oField)" returns an empty object, and then the "SetFocus" fails because it has no object to work with.RPG wrote:Hello
You have to modify the code to your needs. you can not complete copy the code.
Maybe this link is better.
Romke
If you want to try it, simple create a form, a table control with some named field in it, and then try to set the focus to it using a macro. I cannot find a way to do this ... I'm starting to think this is a limitation/bug in ooBase that has no work around?
Dream of Space? Help make it Real.
http://www.open-aerospace.org/
http://www.open-aerospace.org/
Re: Setting focus in table grid with a macro
Hello
I did not have seen the line of Villeroy he say that it is not possible. I think it is true if Villeroy tells that.
I have never tried to select a field in a gridtable. But you can select a column in a grid table
ogrid.select(ogrid.getbyname("TextField1"))
Romke
I did not have seen the line of Villeroy he say that it is not possible. I think it is true if Villeroy tells that.
I have never tried to select a field in a gridtable. But you can select a column in a grid table
ogrid.select(ogrid.getbyname("TextField1"))
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Re: Setting focus in table grid with a macro
I was just trying to say that I'm not able to do what I suggested in the first place because I had dialog controls in mind which are slightly different from bound form controls.RPG wrote:Hello
I did not have seen the line of Villeroy he say that it is not possible. I think it is true if Villeroy tells that.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Setting focus in table grid with a macro
Hello Villeroy
I make the words to free and you did not say it is impossible. It is a mistake from me.
On this moment I do also not have a solution but I come a little shorter to a solution.
For every body
Gridtable
A table in a form give for a lot of people problems. A table control is not a form but a normal control who can contain more controls.
The controls in a table control can have little other properties then they have outside a table control. I have notice that once with a listbox in a table control. There the table control is a control in his own it have also special properties.
You can select a column. get all the values from that column.
Viewmodel of grid
You can move from one column to an other column and set the focus to a column. The only problem I have on this moment is: It seems that you delete the data
Romke
I make the words to free and you did not say it is impossible. It is a mistake from me.
On this moment I do also not have a solution but I come a little shorter to a solution.
For every body
Gridtable
A table in a form give for a lot of people problems. A table control is not a form but a normal control who can contain more controls.
The controls in a table control can have little other properties then they have outside a table control. I have notice that once with a listbox in a table control. There the table control is a control in his own it have also special properties.
You can select a column. get all the values from that column.
Viewmodel of grid
You can move from one column to an other column and set the focus to a column. The only problem I have on this moment is: It seems that you delete the data
Code: Select all
oTableView = GetControlview(thiscomponent,thiscomponent.getCurrentController,oTablemodel.name)
oTableView.CurrentColumnPosition=1
oTableView.setFocus 'CurrentColumnPosition=2
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
-
- Volunteer
- Posts: 828
- Joined: Fri Nov 30, 2007 10:58 am
- Location: Scotland
Re: Setting focus in table grid with a macro
You may find some helpful code by QuazzieEvil at:
http://www.oooforum.org/forum/viewtopic ... 178#281178
The key line for setting the focus on a field in a Grid control is use of the index to the columns position:
This method and the SetFocus() method both require the View of the Grid control. The view is obtained from a combination of the CurrentController of the Writer Form Document and the Model of the Grid control.
You do not specify how the macro is to be triggered. The example is to be triggered by a double click event in the Grid control itself but whatever source event you use, you have to obtain the Model of the grid control and its ancestral Writer Form Document object. The latter is ofter supplied by
If the event source is not linked to the Grid control, I suggest it should always be possible to get that Model of the required Grid control by repeated use of the GetByName() method working down from the Writer Form Document through its Draw Page to the Forms Collection and so on down through named forms and sub-forms.
I should mention that the code also assumes the required record has already been selected in the Grid control.
Though probably not relevant to your need, I should also confess that I find QuazzieEvil's code works better if adjusted merely to use a single click in the Grid control, but I hesitate to question the Master.
http://www.oooforum.org/forum/viewtopic ... 178#281178
The key line for setting the focus on a field in a Grid control is use of the index to the columns position:
Code: Select all
GridControl.setCurrentColumnPosition(1)
You do not specify how the macro is to be triggered. The example is to be triggered by a double click event in the Grid control itself but whatever source event you use, you have to obtain the Model of the grid control and its ancestral Writer Form Document object. The latter is ofter supplied by
Code: Select all
FormDoc=ThisComponent
I should mention that the code also assumes the required record has already been selected in the Grid control.
Though probably not relevant to your need, I should also confess that I find QuazzieEvil's code works better if adjusted merely to use a single click in the Grid control, but I hesitate to question the Master.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
Re: Setting focus in table grid with a macro
That was the solution! The mistake was trying to get the control for the Field (which returned empty) rather than getting the control for the Table and then setting the current column position to the desired field - the field object is not used at all. In my particular case (where the table resides in a sub-sub-form), the final working code is:
Thank you very much
Code: Select all
oDoc = thiscomponent.drawpage.forms
oForm = oDoc.getbyname("Steps")
oSubForm = oForm.getbyname("CompList")
oSubSubForm = oSubForm.getbyname("FailureModes")
oSubSubFormGrid = oSubSubForm.getbyname("TableControl")
oControlView = ThisComponent.CurrentController.GetControl(oSubSubFormGrid)
oControlView.SetFocus
oControlView.setCurrentColumnPosition(2)
Dream of Space? Help make it Real.
http://www.open-aerospace.org/
http://www.open-aerospace.org/
Re: [Solved] Setting focus in table grid with a macro
You can also move to a column relative rather than absolute, with this:
Still looking for how to move to the column by name, starting with something like:
... Thanks, very much for this old thread, still very much useful!
Code: Select all
oControlView.setCurrentColumnPosition(oControlView.getCurrentColumnPosition +4 )
Code: Select all
oControlView.model.getByName("To")
... Thanks, very much for this old thread, still very much useful!
LibreOffice 5.2.5.1 on Linux Jessie 8.6
-
- Volunteer
- Posts: 828
- Joined: Fri Nov 30, 2007 10:58 am
- Location: Scotland
Re: [Solved] Setting focus in table grid with a macro
To move the focus to a particular column in a Grid form control it is necessary to use its View, which has a setCurrentColumnPosition() method but that requires the index number of the column. Only the Model of the Grid form control can get to its columns both by Name as well as by Index. Thus search for the index number of the column where its Model has the required name, so that the View can then use that number for its setCurrentColumnPosition(Index#) method. Some code like this might suit:Still looking for how to move to the column by name, starting with something like:Code: Select all
oControlView.model.getByName("To")
Code: Select all
For i = 0 to oControlView.Count-1
If oControlView.GetByIndex(i).Model.Name = "To" THEN
oControlView.setCurrentColumnPosition(I)
Exit For
End if
Next
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
Re: [Solved] Setting focus in table grid with a macro
Very good. Solved! Thank you.
LibreOffice 5.2.5.1 on Linux Jessie 8.6