[Solved] Update single row in GridControl from subform

Creating and using forms
Post Reply
mic45267
Posts: 9
Joined: Tue Aug 29, 2017 8:41 am

[Solved] Update single row in GridControl from subform

Post by mic45267 »

I have a datatable with many properties. I have created a main form using a GridControl to display only the main properties and a subform displaying all other properties for selected data (main form) record.

The subform and main form have been linked using the master/slave field.

I have expected, that if I change a property in the main or subform, the content of the other form is automatically refreshed.(like in MS Access SplitView). But this is not the case.

Now I have used "Before Record action " event to reload the main/subform. When I do this on the table control, the complete table is reloaded and I loose focus on the currently selected row. This is not convenient for the user.

How can I update a single/selected row of the gridcontrol?
Last edited by Hagar Delest on Fri Sep 08, 2017 10:22 pm, edited 1 time in total.
Reason: tagged [Solved].
LibreOffice: 5.3.5.2
Mac: 10.12.6
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Update single focus row in GridControl from subform

Post by Arineckaig »

I have expected, that if I change a property in the main or subform, the content of the other form is automatically refreshed.(like in MS Access SplitView). But this is not the case.
The Base GUI will automatically update the content of a subform whenever the record pointer is moved in the main form to which the subform(s) is linked. Hence perhaps the simplest means to update a subform linked to a main form containing a grid from control is to select a different record in the grid and then select back again the original record - using either the mouse or the up and down arrow keys.

If this type of double selection is considered cumbersome, add a command button to the subform whose action property is set as "Refresh Form". Though that command button is contained in the subform it can always be located on the form document to appear as part of the main form.

It is essentially a matter of personal judgement which method may come easier for the user.
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
mic45267
Posts: 9
Joined: Tue Aug 29, 2017 8:41 am

Re: Update single focus row in GridControl from subform

Post by mic45267 »

I don't want to do the manual approach. When I do a refresh of the main form (calling "reload") the complete table is loaded and the first row in the table is selected. My intention is only to refresh the currently selected row.
LibreOffice: 5.3.5.2
Mac: 10.12.6
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Update single focus row in GridControl from subform

Post by Villeroy »

Code: Select all

sub FormAfterRecordAction(e)
frm = e.Source
if frm.isFirst() then
  frm.next()
  frm.previous()
else
  frm.previous()
  frm.next()
endif
end sub
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
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Update single focus row in GridControl from subform

Post by Arineckaig »

mic45267 stated:

Code: Select all

When I do a refresh of the main form (calling "reload") the complete table is loaded and the first row in the table is selected. My intention is only to refresh the currently selected row.
Merely for clarity, the main form is not reloaded when its record pointer is moved: only the old record is saved (if changed) and the new linked subform loaded.

Villeroy's macro solution is wholly suitable and reliable. Form change events, however, to trigger macros can sometimes have unexpected results: for example, the Before Record Action event is known to fire twice. That may or may not matter, but developing AOO macros is more complex by comparison with those so readily supplied by MS Access. Hence the suggestion that it is generally easier and safer to avoid AOO macro solutions unless specifically required.
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
mic45267
Posts: 9
Joined: Tue Aug 29, 2017 8:41 am

Re: Update single focus row in GridControl from subform

Post by mic45267 »

Thank you for your input.

Based upon the information from Villeroy, I am now using refreshRow of the form object.

for the Mainform:

Code: Select all

anEvent.Source.getByName("SubForm").refreshRow()
for the Subform:

Code: Select all

anEvent.Source.parent.refreshRow()
LibreOffice: 5.3.5.2
Mac: 10.12.6
Post Reply