How to implement a uno:GotoLine Dispatcher in a Grid on a Dialog

The idea was to implenete a search in a Grid on a Diaalog.
I beleave it can be done loading data in an Array and then try to locate a certain data position
like this:
’ iLine= LocateBinSearch(Array(Idx); stxtPesquisa ): Integer; ’ a iLine
’ Args(3).Value = iLine then goto iLine
oGrid = oDlg.getControl(“tab_g1”).model.GridDataModel ???
oDispatch.executeDispatch(oDocFrm.oGrid ???, “.uno:GotoLine”, “”, 0, args)
The question marks are my great doubts
I found no examples about Grids inside a Dialog box
The mean idea is to performe a uno:gotoline after locate a certain key in an Array(idx) where Idx will be the line to go to.
the nain idea is to get the very same efect as in this example for calc:
Sub GotoRow

dim oDoc as object
dim oController as object
dim oSheet as object
dim oFrame as object
dim oSelection as object
dim oRange as object
dim oCell as object
dim oDispatcher as object

dim lRowNr as long
dim lColNr as long
dim lToRow as long

dim sCellName as string
dim sToRow as string

dim args1(0) as new

oDoc = Thiscomponent
oController = oDoc.getCurrentController
oFrame = oController.Frame
oSheet = oController.ActiveSheet
oRange = oDoc.getCurrentSelection()

lRowNr = oRange.getRangeAddress.StartRow
lColNr = oRange.getRangeAddress.StartColumn

sToRow = InputBox("Please enter a row number:", "Dear User")
lToRow = val(sToRow)
if lToRow <= 0 then lToRow = 1

oCell = oSheet.GetCellByPosition(lColNr,lToRow-1) 'zero based

sCellName = oCell.absolutename
oDispatcher = createUnoService("")
args1(0).Name = "ToPoint"
args1(0).Value = sCellname
oDispatcher.executeDispatch(oFrame, ".uno:GoToCell", "", 0, args1())

End Sub
Can you help? Best Regards

This post appears to be an extended version of Locate or ".uno:GotoLine"
Please do not duplicate posts but rather either delete the original post then post another, or better is to simply edit the original post with the new information.
Please see This is the guide - How to use the Ask site?

Here is a list of dispatch commands →
Have not found a method to do this in a Grid Control. You can select a row:


where oDlg is your dialog and x is the row to select (0 based). However it will not advance to that row if not on the screen already - just select it.


It appears you are putting in a great deal of time & effort to reproduce the table control in a dialog using a grid control. You have not (to my knowledge) stated just what you are attempting to accomplish.
Regardless, instead of this dialog, why not just use a table control in a stand alone form? Eliminates a lot of extra coding and searching for alternatives.

Well i’m new in this world of macros and basic!
I did not knw it was possible to create a standalone form and use it as a dialog
and then, later call it from swriter as it was as Dialog form.
Can you point me to some tutorial.
Best regards.

A domingo, 6/11/2022, 18:13, Ratslinger via Ask LibreOffice <> escreveu:

Once again, you have not in all this time explained what you are trying to accomplish. Therefore I do not know how to give you proper direction. Can only answer you direct question(s) and possibly this is not the best method accomplish your task.
Regardless, a Base form is essentially a Writer document. Here is a link to creating standalone forms → Apache OpenOffice Community Forum - [Tutorial] Standalone Forms / Switchboard - (View topic)

Dear Sir,
I’m note sure if i understand you.

x = BinSearch( myValue , atArray) 'return’s for instance

x = 50
oDlg.getControl(“tab_g1”).selectRow(x) ’ it goes to rec/line 50 (or better 49)
As far as I could validate it works as you said.
Are you saying, that there is no way of scrolling the grid untill vursot move line 99 “automatically by program” because of i’ve 15 visible lines
in the grid and the others 50/70, including the one i do need to get is hidden? Is that for a fact?
Because if the first 15 in the screen, to reach 49 i should move down 49+15 or at least 49 + (15/2)lines/rows.
There is no way of scrolling down +/- 57 lines?! In order to put th one i need visible in the grid
Sorry!I mean no disrespect but i foud it hard to beleave.there muito bem a way of scrolling the grid rows
By program macro.
Best regards

Mário Agostinho Reis

Esta mensagem contém informação de natureza confidencial e é
exclusivamente dirigida ao(s) destinatário(s) indicado(s). Se, por engano,
receber este email agradecemos que não o copie nem o reenvie e que nos
notifique do ocorrido através do email de resposta.

Ratslinger via Ask LibreOffice <> escreveu no dia domingo, 6/11/2022 à(s) 01:15:

I found no way to scroll down/up even one line in a grid control.
Only method (and I do not like) is to either load the grid at the point of the selected item or display the selected item data in a different control in the dialog.
Even looked at initiating stimulated keystrokes but there is no ASCII value for Arrow down/up or even page down/up.
Again, do not know why you are so captivated with the grid control. You have not provided any means of what you are trying to accomplish.

Did discover how to go to a cell which should suffice:

  oView = oDlg.getControl("YourGridName").getView()
  oView.goToCell(Ener_Column_here, Enter_Row_here)

Edited 2022-11-12 - Had Col/Row reversed
Also, you can set the focus to the grid (if it was lost to another function) with:

1 Like

To place together a few items, attached is a sample Calc file. Has a push button to open a dialog.
The dialog has a Grid control with some contrived data in it. There is a numeric control in the lower left. Entry of a number and using the Search button will find the number of occurrences in first data column, highlight the first row it is found in and set focus there.
GridSearchSample.ods (12.7 KB)

This design:

oDlg.getControl("MyGrid").goToCell(0, n)

should also work.

Hi every body.
Sorry Rastlinguer you’ve been very helpful, but you missed something on the fly! You are wrong!
Moving down or up in a Dialog Grid is possible and down. So far it work’s for sure.
It fly’s over the grid positioning itself on the line where the searched value is found

I Created a NewCommand Button “BtnLocate”

Sub Value_Locate_actionPerformed( oEv As )
Dim n, i, iLast as Integer
Dim aLinha as Array

’««««« I started here… The array is loaded while loading the grid from oResultSet.getStrin(I)
’ n= MyBinSearch(myKey, atMyArr) ’ Returns 80 assuming from TopDown (Later on i will care about BottomTop)
n = 80 ’ where i found my search key at the Array
i= oDlg.getControl(“tab_g1”).getCurrentRow -1 ’ Since i start at 0+1 one is zero
n = n - i
’'oDlg.getControl(“tab_g1”). gotoline(n): Doesn’t work, probably, my mistake! oDlg.getControl(“tab_g1”).goToLine(n) ?? Not found goToLine something i missed ‘’ for sure uno:GotoLine .’ i’ve goto to fixed it later

’ BUT this works
’ goToCell(0, n) => HowEver work’s perfect automatically moves down the cursor to the desired line; i just have to tune it a little bit since 0 vs 1 start

’'Now I just have to accomplish the all rest, and put it all together

oDlg.getControl(“tab_g1”).goToCell(0, n) ’ it goes exactly where i do need

oDlg.getControl(“tab_g1”).selectRow( n )

if oDlg.getControl(“tab_g1”).hasSelectedRows() then
aLinha = oDlg.getControl(“tab_g1”).model.GridDataModel.getRowData(oDlg.getControl(“tab_g1”).getCurrentRow)
End If

’ So in a range of 100 “Az…” loaded/present at the grid in the screen “I do not have to reload the grid from the new Sql parameters”.
’ I just need to find a line where the searched value is present and then oDlg.getControl(“tab_g1”).goToCell(0, Line) line 55 for example is "AZÓRIA… "
’ This what is needed because most of the time the end user ony know’s small part of the information i need’s to achieve!
’ I hope now it is now clear for everybody (please take a look at the print’s bellow)
End Sub 'Value_Locate_actionPerformed( oEv As )

Thank you sokol92 . So far so good It seams to work perfect.

Vladimir Sokolinskiy via Ask LibreOffice <> escreveu no dia domingo, 13/11/2022 à(s) 14:21:

Not sure what you are stating. Your solution seems to be what I posted in the comment above five days ago (edited four days ago) and followed that up with a sample demonstrating the find - and more including searching for values. Yes I did originally state there was no way to scroll up/down and there still isn’t. I did however show how to simulate this with the .goToCell method. Please explain where I was wrong or did you simply ignore my further posts?

Further, I had actually given you a link to this information in early October of 2022 → Controlo de Tabela em um dialog; SO: c/ WIN10, LibreOffice - #7 by Ratslinger
You need to follow down a number of levels of links (and until my edited comment even I did not follow enough) you will come to this information: Interface XGridControl


Screenshot at 2022-11-17 10-52-18

Thank you for your help, once more.
Now that I’m calmer because I’ve accomplished the task I set myself, I’m going to dedicate myself to cleaning up the code and perfecting it.
Then I put together a complete example with half a dozen records and share it so that no one goes through the trouble I went through.
Meanwhile when closing the Dialog I’ve a new error: “Property or method not found: ($ARG1).”
So far could not find the cause! Any ideas that might help?

Ratslinger via Ask LibreOffice <> escreveu no dia quinta, 17/11/2022 à(s) 18:03:

I understand you are looking for more help.
However, why have you not responded to my last two comments? This has been a pattern for you - not responding to questions asked.

Although noted yet again, have you even looked at my sample to see my dialog? It has no problems. With yours, have no idea how you have coded it. You have only presented pieces.