[Solved] Setting focus in table grid with a macro

Creating a macro - Writing a Script - Using the API

[Solved] Setting focus in table grid with a macro

Postby void64 » Thu Jan 28, 2010 10:20 pm

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/
void64
 
Posts: 30
Joined: Sun Jun 21, 2009 9:57 pm

Re: Setting focus in table grid with a macro

Postby Villeroy » Thu Jan 28, 2010 10:33 pm

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24257
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Setting focus in table grid with a macro

Postby void64 » Thu Jan 28, 2010 11:37 pm

Villeroy wrote:The table (grid) control bundles other controls in columns. Focus a control within the grid.


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.

Clipboard02.jpg
Clipboard02.jpg (17.05 KiB) Viewed 9222 times


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/
void64
 
Posts: 30
Joined: Sun Jun 21, 2009 9:57 pm

Re: Setting focus in table grid with a macro

Postby Villeroy » Fri Jan 29, 2010 12:02 am

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.

 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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24257
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Setting focus in table grid with a macro

Postby void64 » Fri Jan 29, 2010 1:55 am

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:

Code: Select all   Expand viewCollapse view
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


But when executing it nothing seems to happen - where did I go wrong?
Dream of Space? Help make it Real.
http://www.open-aerospace.org/
void64
 
Posts: 30
Joined: Sun Jun 21, 2009 9:57 pm

Re: Setting focus in table grid with a macro

Postby RPG » Fri Jan 29, 2010 4:19 am

Hello

read this for understanding a grid control.

and this for setting focus

Romke
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2096
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Setting focus in table grid with a macro

Postby void64 » Fri Jan 29, 2010 6:19 pm

RPG wrote:Hello

read this for understanding a grid control.

and this for setting focus

Romke


Thanks, that was helpful! I tried using this code snippet to set the focus:

Code: Select all   Expand viewCollapse view
oController = ThisComponent.CurrentController
oForm = ThisComponent.drawpage.forms.GetByName("FailureModes")
cControl = oForm.GetByName("CauseName")
oControlView = oController.GetControl(cControl)
oControlView.SetFocus  'sets the focus


However the 2nd line fails ("no such component") because the form containing the table grid is a sub-form. Can you tell me how to modify this code so I can access the table in the sub-form (rather than the main form)?
Dream of Space? Help make it Real.
http://www.open-aerospace.org/
void64
 
Posts: 30
Joined: Sun Jun 21, 2009 9:57 pm

Re: Setting focus in table grid with a macro

Postby Villeroy » Fri Jan 29, 2010 6:32 pm

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)?

It's all in Romke's first link: viewtopic.php?f=39&t=24013&p=109535&hilit=grid+control#p109535 (last snippet).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24257
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Setting focus in table grid with a macro

Postby void64 » Fri Jan 29, 2010 6:44 pm

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   Expand viewCollapse view
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/
void64
 
Posts: 30
Joined: Sun Jun 21, 2009 9:57 pm

Re: Setting focus in table grid with a macro

Postby RPG » Sat Jan 30, 2010 2:11 am

Hello

You have to modify the code to your needs. you can not complete copy the code.


Maybe this link is better.
Romke
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2096
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Setting focus in table grid with a macro

Postby void64 » Sat Jan 30, 2010 3:24 am

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


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.

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/
void64
 
Posts: 30
Joined: Sun Jun 21, 2009 9:57 pm

Re: Setting focus in table grid with a macro

Postby RPG » Sat Jan 30, 2010 4:39 am

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
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2096
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Setting focus in table grid with a macro

Postby Villeroy » Sat Jan 30, 2010 8:40 am

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.


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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24257
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Setting focus in table grid with a macro

Postby RPG » Sat Jan 30, 2010 2:33 pm

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

Code: Select all   Expand viewCollapse view
oTableView = GetControlview(thiscomponent,thiscomponent.getCurrentController,oTablemodel.name)
oTableView.CurrentColumnPosition=1
oTableView.setFocus 'CurrentColumnPosition=2


Romke
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2096
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Setting focus in table grid with a macro

Postby Arineckaig » Sat Jan 30, 2010 9:27 pm

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:

Code: Select all   Expand viewCollapse view
GridControl.setCurrentColumnPosition(1)

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
Code: Select all   Expand viewCollapse view
FormDoc=ThisComponent

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.
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).
OOo 4.1.1 on MS Windows XP MySQL and HSQLDB
Arineckaig
Volunteer
 
Posts: 822
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Setting focus in table grid with a macro

Postby void64 » Sat Jan 30, 2010 9:59 pm

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:

Code: Select all   Expand viewCollapse view
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) 


Thank you very much :D
Dream of Space? Help make it Real.
http://www.open-aerospace.org/
void64
 
Posts: 30
Joined: Sun Jun 21, 2009 9:57 pm

Re: [Solved] Setting focus in table grid with a macro

Postby Koa » Tue Mar 21, 2017 4:50 am

You can also move to a column relative rather than absolute, with this:

Code: Select all   Expand viewCollapse view
oControlView.setCurrentColumnPosition(oControlView.getCurrentColumnPosition +4   )


Still looking for how to move to the column by name, starting with something like:

Code: Select all   Expand viewCollapse view
oControlView.model.getByName("To")



... Thanks, very much for this old thread, still very much useful! :bravo:
LibreOffice 5.2.5.1 on Linux Jessie 8.6
Koa
 
Posts: 11
Joined: Sun Jan 15, 2017 11:53 pm

Re: [Solved] Setting focus in table grid with a macro

Postby Arineckaig » Tue Mar 21, 2017 2:07 pm

Still looking for how to move to the column by name, starting with something like:
Code: Select all   Expand viewCollapse view
oControlView.model.getByName("To")

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:
Code: Select all   Expand viewCollapse view
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).
OOo 4.1.1 on MS Windows XP MySQL and HSQLDB
Arineckaig
Volunteer
 
Posts: 822
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: [Solved] Setting focus in table grid with a macro

Postby Koa » Sat Mar 25, 2017 2:28 am

:-) Very good. Solved! Thank you.
LibreOffice 5.2.5.1 on Linux Jessie 8.6
Koa
 
Posts: 11
Joined: Sun Jan 15, 2017 11:53 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 11 guests