Creating an UpdateGridControl
An UpdateGridControl is a specialized Form control that enables you to add child records at the same time you are adding a parent record. Use this control when you have a one to many relationship between a parent record and its children, and when you might create a number of child records at the same time.
To create an UpdateGridControl, use the following steps:
In this exercise, we create a new [01] form to be used only for adding new records, and attach a grid to the bottom of this form to enable the user to add multiple child [02] records.
This exercise is a multi-step (7+ exercise) that touches:
Add Data Object
Add a new Data Object on your parent Object that points to your child [02] table:
Once you are done, your parent object will have two data objects:
Please note that the netFORUM Object Wizard creates any possible data objects based on relationships defined in the database tables. After the Object Wizard runs, however you must deselect the do not save data checkbox (as it will default to checked) for the one-to-many data object as shown. Since we did not run the Object Wizard for the first object, you need to manually add the data object.
With the data object configured in this manner, when you design a form for the TV Network object, the New Control to Add drop-down list will automatically include an Update Grid for your TV Network Customer data object. This will be described more in a section below.
Create Grid Form
Next, from the child Object, you must add a new Form for the grid control definition and design the form. You might want to name the form TV Network Customer - grid . This form will not be a conventional form; its only purpose will be to define the UpdateGridControl.
Next, go to this new form and Design it. You'll probably want to use the copy from form feature to copy all the controls from the original form.
Design Grid Form
Design the new grid form. Add form controls in the desired order from left to right. The field headers on the grid will be the captions/labels. You can use the standard control features such as read only, auto postback, etc. You do not need to line these controls up carefully; at run time they will be sized and aligned properly.
Please note that although the foreign key that points to the network key x02_x01_key is required to save a TV Network Show, we did not add this field in the grid control definition. The framework manages this automatically.
Also, copy the FormKey of this new Form to your clipboard (you might want to paste it somewhere, such as in a Notepad, for use later). You will need it later for pasting.
Develop a new Add Form for the Parent Object
Unless you write special .NET code, you cannot use an UpdateGridControl when editing an existing record. The UpdateGridControl will work only when adding a new record.
Therefore, add a new form for the parent object, specifically for adding. You might want to put the word "- add" at the end of the form description to denote this.
Modify Group Item Link for Add Link
You will also need to go to the Group Item for the parent and modify the Group Item Link for the "add" and point that link to this new "add" form.
Add the UpdateGridControl to your Parent Form
Finally, you will design the new parent form (TV Network - add) that will have the UpdateGridControl.
You will add a new control by selecting the Update Grid created by the one-to-many data object. The Update Grid will appear in the New Control to Add dropdown as follows: Avectra :: Update Grid - << description of the data object >>.
Once you have added the control to the form, the designed form will look like this:
Resize the Grid Control as you wish. You should make it as wide as the form allows, and tall enough to enable a user to view at least several records without needing to scroll up and down. Paste (Ctrl-V) the FormKey you copied earlier into the URL/Image Path/Data field to tell netFORUM which form to use as the Grid Control definition.
To re-cap some setup issues, please remember these key requirements for using an UpdateGridControl:
- The Data Object on the parent that points to the child table is one-to-many.
- The data object does not have "do not save data" checked.
- The foreign key control for the child (in this case, x02_x01_key is not added as a control in the update grid definition form.
- The UpdateGridContol only works for adding a new parent record, and not for editing an existing parent record.
Test New Form
Navigate to the module and make sure that you can add a new record with zero, one, or several child records.
Before
You can add a parent, save it, and then manage child records.
After
User can add a parent and multiple child records at the same time:
UpdateGridControl