So I'm trying to build a form dynamically and use a ListView to display data. I want to be able to grab the selections that the user selects when the button is pressed. Those values are then used to passed to the place where the form was called and used to write the method for the function. Meaning, this doesn't go in the AX front end and is used in the backend for helping programmers quickly build methods. The form builds, the ListView appears and is populated correctly and the button appears. However, I can't get the button to work. I've tried different types of buttons and the way it is now at least when the button is clicked it does absolutely nothing. I do have a method defined:
void xButton_clicked()
{
info("button clicked");
}
This is the init() method of the form. Again, it's a dynamic form that populates the ListView based on the elements of an array that are passed to it.
public void init()
{
Form xform;
FormRun xformRun;
FormBuildDesign xdesign;
FormBuildListControl xlistView;
FormBuildGroupControl xlistGroup;
FormFunctionButtonControl xokButton;
FormBuildButtonControl xcancelButton;
FormListControl xlistControl;
FormListItem xlistItem;
int xlistId;
int xi;
Args xargs;
int xarrayLength = xfields.lastIndex();
int xitemCounter;
int xformWidth = 300;
int xoffset = 30;
//build the form using standard strategy:
//form -> design -> group -> controls -> run
xform = new Form();
xform.name("FindMethod Field Select");
xdesign = xform.addDesign('design');
xdesign.caption("Form Generated from Form");
xdesign.width(xformWidth);
xdesign.statusBarStyle(1);//gets rid of bottom record navigation
xlistGroup = xdesign.addControl(FormControlType::Group, 'Group1');
xlistGroup.addControl(FormControlType::Group, "Group");
xlistGroup.caption("List of Field Names");
xlistGroup.width(xformWidth - xoffset);
xlistGroup.heightMode(1);
xlistView = xlistGroup.addControl(FormControlType::ListView, "List");
xlistId = xlistView.id();
xlistView.singleSelection(false);//allows the use of CTRL or SHIFT when making selections
xokButton = xdesign.addControl(FormControlType::Button, 'xButton');
xokButton.text("OK");
xokButton.width(100);
xokButton.height(30);
//store the newly created form for use at runtime
xargs = new Args();
xargs.object(xform);
//create the form at runtime
xformRun = classFactory.formRunClass(xargs);
xformRun.run();
xformRun.detach();
//setup the listview
xlistControl = xformRun.control(xlistView.id());
xlistControl.viewType(FormListViewType::Report);
xlistControl.heightMode(1);
xlistControl.addColumn(1, new FormListColumn("Field Name", 1, 250));
xlistControl.widthMode(FormWidth::ColumnWidth);
xlistControl.rowSelect(true);
//populate the listview by looping through the array of field names
for(xi = 1; xi <= xarrayLength; xi++)
{
xlistItem = new FormListItem(xfields.value(xi));
xitemCounter = xlistControl.addItem(xlistItem);
}
super();
}
And the run() method:
public void run()
{
element.controlMethodOverload(true);
super();
}