AX forms commonly use the gridview control for grid based data, this is great for showing data from tables with fixed columns, however its not ideal when working with dynamic columns and rows.
The answer... the "table" form control allows you to define the columns, rows, and data for each cell from code. Each cell can also be color coded. Check out the "tutorial_Form_Table" form in the AOT for an example.
Start by adding a table control to the form. You can define how many columns and rows you want in your table but this will be overridden later by code. When the table is drawn the system calls the editControl() method on the table to determine which control to put in each cell. We will want to start with three different controls:
"Blank" stringEdit for empty cells, this has the background color set to white and allowEdit is yes.
"Invalid" for cells that cant be modified, the background color is set to grey and allowEdit is set to No.
"Blocked" for cells that are booked, this has a background color set to red.
When the systems calls editControl(int column, int row) to draw the table one of these form controls will be returned, override this method to return the correct control for the cell, the text can be set in this method by calling table.cell(column, row).data("Text").
The table row labels and column labels can be set as such:
meTime = rowMap.getEnumerator();
time = meTime.currentValue();
timeStr = time2str(time, TimeSeparator::Colon, TimeFormat::AMPM);
timeStr = substr(timeStr, 1, 5) + substr(timeStr, 9, 99); // Remove seconds from time display
meCol = colMap.getEnumerator();
SWM_Resources = SWM_Resources::find(meCol.currentValue());
table.setColLabel(meCol.currentKey(), strfmt("%1", SWM_Resources.Description));
Interacting with the table:
Event methods can be defined for each stringEdit control on the table. The method can determine the selected cell by using the table.column() and table.row() methods. On the "blank" cells control add a showContextMenu() method that allows a user to right click on any available cell and select "Block this timeslot" to change the cells status to blocked. The editControl() method will now return the "block" string edit control for that cell and text can be typed into the cell. The "modified" method can then be used to detect and save changes to the text that is typed directly into the cell.
In the case that only specific jobs can be booked into the timeslots, rather than freetext, then the lookup method on the control can be used to open a lookup form to select a specific job for the timeslot.
The table formcontrol makes a very powerful tool for managing scheduling while giving visual feedback of resource availability. Because it is controlled through code it can be customized to fit many different purposes.. dates could be used for columns or it could be linked into any existing tables in AX.