Your application has one or more actions that may be applied to one or more selected items in a grid. GeneXus lets you scan all selected items in a Grid with the for each selected line command. The code to execute an action on all selected items will look as follows.
for each selected line [in <GridName>]
: The Procedure object
must have only input parameters
(output or hybrid parameters are not allowed)..
Adding multiple selections#
To further explain the use of multiple selection actions, we suppose that we have a set of customers and we want to apply a tax or 25% for some of them depending on their total amount.
Step 1 - Setting the UI behavior#
Previously, we create a Customer transaction object as follows and we apply the WorkWithDevices pattern.
In the Grid control from the List section of WorkWithDevicesCustomer, we will set the following properties:
- Default Action property = <default>.
In this case, the end user is able to see the Detail section of the WorkWithDevicesCustomer when tapping in a register.
- Enable Multiple Selection property = True
For allowing multiple selections over Customer grid in the List Node.
- Show Selector property = Always.
It sets the user interface behavior for multiple item selections as always show its selector.
Step 2 - Creating the action#
Create a new action called "Add tax" (right click on the Application Bar > Insert Button).
This action will perform an ApplyTax procedure for updating the CustomerAmount by adding an interest of 25% on the selected items. In this procedure, we have to write the following code:
CustomerAmount = CustomerAmount * 1.25
The procedure must have a parm rule as it is shown below for automatically filter items in the for each command.
3. Writing the action execution code#
Finally, we have to write the section code associated with the action 'Add tax' on the Event section as follows.
Event 'Add tax'
For each selected line in Grid1
- For SDT or BC collection based Grids, the way to access to each item is by the CurrentItem runtime property.
For each selected line in Grid1
where &Customer is a variable based on an SDT or BC item.
Application runtime behavior#
1. We have to select the items that we would like to update. Every item can be selected by tapping on the left check-box.
2. Once you finish the selection, tap on "Add tax" action for executing the action apply the 25% tax interest.
3. After the refresh of the device, we can see the total amount has changed correctly.
- If you have an action with several for each selected line over different Grids, the behavior of the User Interface is the platform default.
- An attribute used in a for each selected line command must be present in the grid on the form to works correctly.
- In the for each selected line in <grid> command, the grid's name is optional when you have only one grid in the SD Panel or WorkWithDevices object.
- If the grid row theme class has highlighted background color, this color will be used to mark the selected items.
- For Android devices, the selection user interface may depend on the operative system version.
- Enable Multiple Selection property is available as of GeneXus 15 Upgrade 6. For previous upgrades, you must set Selection Flag property.