Axaptapedia is now maintained by AgileCadence For more information please click here.

Multiple grid selections

From Axaptapedia
Jump to: navigation, search

Dealing with multiple grid selections in Axapta is much easier than it first appears.

Ensure that the MultiSelect property is set to true on any relevant buttons (ie buttons that should operate on multiple rows)

Use the following code to process the rows. Note that this will work whether the user has selected only a single, or multiple rows. The getFirst method decide if you get the active row (parameter= true) or multiple rows (parameter = false).

for (buffer = table_ds.getFirst(true) ? table_ds.getFirst(true) : table_ds.cursor(); buffer; buffer = table_ds.getnext())
// Some processing

In the example, table_ds is used to signify the datasource and buffer should be declared as the correct table type.

For example, if you were writing this code on the SalesTable form, dealing with selected sales order header, you would use an instance of SalesTable for buffer, and SalesTable_ds as the datasource.

If the code is being run from another location, such as in a class method, then the easiest option is to pass through the current record from the form, and retrieve the datasource from that record using the datasource() method.

For example, if we have a class being called from a MenuItemButton on the form, then args().record() will contain the currently selected record. In this case, we can use the following code in main() of our class:

SalesTable     salesTable;
FormDataSource salesTable_ds;

salesTable = _args.record()
if (salesTable.dataSource())
  salesTable_ds = salesTable.dataSource();

We can then use the standard code above, with salesTable for the buffer, and salesTable_ds for the datasource.

See also[edit]