How Do I Implement a Choice Control Whose Data Comes from a Database Table? (Magic xpa 3.x)
Often it is useful to have a control where the data is chosen from a database table. That way, when the choices change because of table updates, the choices change automatically also.
In this example, we are choosing a studio from the studio table. While the user sees only the studio name, the studio code is what is brought back into the task. Let’s see how to do it.
-
First, create the virtual that will hold the data. In our example, that is v.Studio Code.
-
Drag the Combo Box (or other choice control) from the Toolbox and drop it onto your form.
-
Select the virtual for the Data property of the choice control (L, in our example).
-
Zoom from the Source table property to select the table you want to use. In our example that is Studios.
-
Zoom from the Display field property to select the field you want to show to the user. In our example, we used Studio Name.
-
Zoom from the Linked field property to select the field you want brought back in to the virtual. In our example, that is the Studio code field.
-
Zoom from the Index property to select the display order of the fields. If you are using Field ranges, it is important that the index match the range, or you will have performance problems. For instance, you don’t want to have the index search the table by Studio code, while your field range is filtering by Zip code.
-
Zoom from Field ranges to limit the number of entries in the choice control, if applicable. For instance, we might want only the Studios that are located in California.
Now, when the task is run, the choice control will be populated by live data from the table.
Note: If the table is large, using the table in a choice control can present a performance issue. This option is best used for smaller tables, or tables where there are good efficient indexes. Also, note that the tables used in choice controls do not show up on the declared tables list.
The Online and Rich Client Samples projects (program HG21 and RHG21)