Question

I have 3 tables in a single form, they use SQL queries to select the data. I need to refresh them somehow, but nothing works.

E.g. this doesn't work at all:

oBaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
oDataSource = oBaseContext.getByName(dbName)
oCon = oDataSource.getConnection("", "")
oCon.getTables().refresh()

And this updates only the first table:

oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
oFrame = ThisComponent.getCurrentController().getFrame()
oDisp.executeDispatch(oFrame, ".uno:Refresh", "", 0, Array())

How do I update them all?

Was it helpful?

Solution

Oh my god, it was so easy, I feel dumb now:

Sub reloadAllTables
    Dim Forms : Forms = ThisComponent.DrawPage.Forms
    Dim i%
    For i = 0 To Forms.getCount()-1
        Forms.getByIndex(i).reload()
    Next
End Sub

OTHER TIPS

Reloading forms doesn't refresh tables, table controls are refreshed by using .refresh on each column, for example-

SUB refreshTables(oForm as object)
DIM cnt as integer, cnt2 as integer, tot as integer, tot2 as integer
DIM oFormObj as object

'get number of form object
tot = oForm.getCount - 1
IF tot > -1 THEN
    FOR cnt = 0 TO tot
        'next form object
        oFormObj = oForm.getByIndex(cnt) 
        'is object a table control AKA grid control
        IF oFormObj.ImplementationName = "com.sun.star.comp.forms.OGridControlModel" THEN
            'refresh each column
            tot2 = oFormObj.getCount - 1
            IF tot2 > -1 THEN
                FOR cnt2 = 0 TO tot2
                    oFormObj.getByIndex(cnt2).refresh
                NEXT
            ENDIF
        ENDIF
    NEXT
ENDIF
END SUB
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top