This is a sample code to add run time control in axapta form. This is not 100% accurate code but this can help you to create run time control.
There is no guarantee that run time control will work perfectly in Ax I tried it but did not get much success on this but what success I get I shared here.
There is no guarantee that run time control will work perfectly in Ax I tried it but did not get much success on this but what success I get I shared here.
public void init()
{
int i;
int a;
int d;
int j=0;
str lable;
DictTable dictTable;
TableId tableID;
//TestId testId1;
FormStringControl fStringTestID;
str GetParm;
str ParmCaller;
/////
FormBParams formBParams;
Array items;
object formRunCaller;
//FormRun formRun;
//Args args;
;
// if( element.args() )
// {
// get string parameter
// testId1= this.TestID() ;
formRunCaller = element.args().caller();
if(formRunCaller)
{
testId1=formRunCaller.MethodA();
}
// }
//ssss
/*if(element.args())
{
testId1=element.args().parm();
}
if(element.args().caller())
{//element.args().record().update();
_Question1 = element.args().record();
// _Question1.update();
testId1=_Question1.TestID;
}*/
i = 1;
d=1;
a=0;
lable = "";
formTabControl = this.form().addControl(FormControlType::Tab,"MainTab");
formTabControl.heightMode(1);
formTabControl.widthMode(1);
formTabPageControl = formTabControl.addControl(FormControlType::TabPage,"MainTabPage");
formTabPageControl.caption("Test");
this.controlMethodOverload(true);
formGroupControl = formTabPageControl.addControl(FormControlType::Group, "MyGroup");
formGroupControl.caption("Test");
while select * from _Question where (_Question.TestID==testId1) //order by RecId
{
a = 1;
while select * from answer where answer.GroupId == _Question.GroupId
{
if(_Question.ControlId == QuestionControlInputType::CheckBox)
{
formCheckBoxControl = formGroupControl.addControl(FormControlType::CheckBox, num2str(i,2,0,0,0) + num2str(a,2,0,0,0) + "Question" );
formCheckBoxControl.label(answer.Text);
}
if(_Question.ControlId == QuestionControlInputType::RadioButton)
{
formRadioControl = formGroupControl.addControl(FormControlType::RadioButton, num2str(i,2,0,0,0) + num2str(a,2,0,0,0) + "Question" );
formRadioControl.caption(answer.Text);
}
a = a+1;
}
if(_Question.ControlId == QuestionControlInputType::Text)
{
formStringControl = formGroupControl.addControl(FormControlType::String, "QuestionStr" ); //num2str(i,2,0,0,0) +
formStringControl.label( num2str(i,2,0,0,0) + ". "+ _Question.QText + ":");
}
else if (_Question.ControlId == QuestionControlInputType::Grid)
{
formStaticTextControl = formGroupControl.addControl(FormControlType::StaticText, "Question" );//num2str(i,2,0,0,0) +
formStaticTextControl.text(num2str(i,2,0,0,0) + ". "+ _Question.QText + ":");
formDataSource = new FormBuildDataSource();
// this.form().addDataSource("_dataGridTbl");
formDataSource = this.form().dataSource(d);
tableID =_dataGridTbl.TableId;
dictTable = new DictTable(this.form().dataSource(d).table());
formDataSource.name( num2str(i,2,0,0,0) + "QuestionDb");
formDataSource.name(this.form().dataSource(d).name());
formDataSource.name(dictTable.name());
// formDataSource.table(this.form().dataSource(d).table());
formDataSource.autoQuery(true);
formGridControl = formGroupControl.addControl(FormControlType::GRID, "QuestionGri" );//num2str(i,2,0,0,0) +
formGridControl.dataSource(dictTable.name());//();
formGridControl.widthMode(1);
formGridControl.heightMode(1);
this.showFields(tableNum(_dataGridTbl), formGridControl, formDataSource);
d =d+1;
}
i = i+1;
}
formButtonControl = this.form().addControl(FormControlType::Button, "CmdSave");
formButtonControl.text("Save");
form1 = this.form();
//new
/* while select _TestRows where _TestRows.TestId==testId1
{
j=j+1;
if (j==1)
{
while select _TestRows1 where _TestRows1.TestId==testId1 && _TestRows1.ColumnNo=="1"
{
tmp_DataGridTabl.TestID=testId1;
tmp_DataGridTabl.QId="15";
tmp_DataGridTabl.Col1=_TestRows1.RowDescription;
tmp_DataGridTabl.insert();
}
}
}
select forupdate tmp_DataGridTabl;*/
// formGridControl.dataSource(tmp_DataGridTabl);
//new
// formButtonControl = this.form().addControl(FormControlType::Button, "CmdShow");
// formButtonControl.text("Show");
super();
}