Base form problem with refreshing listbox

I have a form that has a main form and a sub form. In the form there is also a table that is connected to a listbox in the subform. When i add a new item to the table it should be possible to refresh the listbox in the subform. I see two buttons, one (refresh) can be used to refresh the table with the new item. According to the base handbook the listbox can also be refreshed by finding the listboxfield in the subform.
When I do so, the button ‘refresh control’ sometimes becomes active, but a lot of times not at all. The only way to see the new field in the listbox is to close the form and reopen it.
How should these buttons be used or is there another way?

If there is a new entry in the mainform the subform is inactive. So the mainform must be saved. Then you could refresh the listbox in the subform.

The other button you are using is the reload of the mainform, not a refresh of the table.

I would try to get the refresh when content of the mainform has been saved. Something like this:

SUB RefreshListbox(oEvent AS OBJECT)
oForm = oEvent.Source
IF hasUnoInterfaces( oForm, "com.sun.star.form.XForm" ) THEN
oListBox = oForm.getByName("SubForm").getByName("ListBox")
oListBox.refresh
END IF
END SUB

There are 2 different implementations happening when the form will be saved. You will need only the one, which is filtered by IF …

The name for SubForm and ListBox must be the names of the controls you will see in form navigator or when looking at the properties of the form and of the listbox.

Refresh anything anywhere without any code editing: [Base, Python] Tiny Macro Refreshing Forms, List/Combo Boxes