Multiselection Design Pattern
Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
Buttons and their underlying menu items must support multiselection in grids to the greatest possible extent. This programming pattern can be used to make functionality multiselection-enabled.
Situation
The user has selected several records in a grid, and you want to make it possible to process exactly the selected records.
Solution
You must traverse the multiselected records, if any. If there is no multiselection, you must process only the current record.
Implementation
The Form data source object contains methods to traverse the cached and potentially selected records in, typically, a grid on a form.
One option is to make a for loop that goes through the selected records, or just the current record, as shown in the following example.
Example
The following code example shows items that could be found on a form with the xRefReferences data source.
void clicked()
{
xRefReferences xRefReferencesEdit;
;
// Are there any marked records?
for (xRefReferencesEdit = xRefReferences_ds.getFirst(1)
? xRefReferences_ds.getFirst(1)
// If yes, get the first marked record,
// otherwise, use the current record.
: xRefReferences;
// Continue as long as there are records to work on.
xRefReferencesEdit;
// Get the potential next marked record.
xRefReferencesEdit = xRefReferences_ds.getNext())
{
// Do processing with xRefReferencesEdit.
...
}
}
See also
Microsoft Dynamics AX Design Patterns
Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.