A common pattern you tend to find in maintenance forms is the ability to open another form so you can add/edit/maintain some list of items. When you return back to the calling form you want to refresh a combo or grid to reflect the changes. The way most of us do this is to make the maintenance form modal. When you call it, code execution stops until the form is released. That works but it can break down if you find yourself more than 1 level deep in maintenance forms – the user can’t easily move windows out of the way to see information and you’ll occasionally find that the wrong form has somehow gotten focus leaving you stuck (unable to get focus back to the correct form).
Here’s an example. The user starts off on the Client Maintenance form, then clicks on the Commissary button (military grocery store) to select which stores are associated with this client. Then they click on the Commissary button again if they want to add/edit a new store. When they close this form we want to refresh the second form.
Again, the normal way you might do this is to make the third form modal.
DO FORM CommissaryMaintenance * When the form is closed the code below is run which saves and refreshes * the options shown. ThisForm.SaveAndRefresh()
An alternative to this code (and making the form modal) is to do something like this instead:
DO FORM CommissaryMaintenance NAME loForm BINDEVENT(loForm, “Destroy”, ThisForm, “SaveAndRefresh”)
Now the form can stay modeless. We’re taking advantage of VFP’s BINDEVENT command. When the form is closed and the Destroy() event fired we’ll fire the SaveAndRefresh() method which refreshes the form. It’s simple and avoids the problems mentioned above.
One suggestion is to add code in the calling form to set focus back to itself (in case you are mixing and matching modal and non-modal forms). Ex. in the SaveAndRefresh() method you might want to do something like this:
ThisForm.grdList.SetFocus()
That will ensure that your form actually gets focus and back where the user is expecting to be.
This all works great, but what if you want to update the form as new items are add, not just when the form closes? If you modify the maintenance form to call an empty method after a successful save, ex. create a method named SaveSuccessful() you can now bind to this method instead of Destroy().
BINDEVENT(loForm, “SaveSuccessful”, ThisForm, “SaveAndRefresh”)
With only an extra line or two of code you can get rid of the modal form and still have your calling for get easily updated/refreshed when things are changed.
Remember Me
a@href@title, b, i, strike