Create fields dynamically on the form ax 2012
public void clicked()
{
Form tableBrowser;
FormBuildDataSource formBuildDataSource;
FormBuildGridControl formBuildGridControl;
FormBuildDesign formBuildDesign;
DictTable dictTable;
FormRun formRun;
Args args;
Args browserArgs;
dictTable = new DictTable(tableNum(CustomTable));
browserArgs = new Args();
browserArgs.name(formstr(CustomForm));
formRun = classfactory.formRunClass(browserArgs);
tableBrowser = formRun.form();
formBuildDesign = tableBrowser.design();
super();
formBuildDataSource = form.dataSource(1);
formBuildGridControl = formBuildDesign.control('Grid');
formBuildGridControl.dataSource(dictTable.name());
formBuildGridControl.allowEdit(true);
element.addField(tableNum(CustomTable),fieldNum(CustomTable,Occupation),formBuildDataSource,formBuildGridControl,true );
args = new Args();
args.object(tableBrowser);
formRun = classfactory.formRunClass(args);
formRun.enableCountryRegion(false);
formRun.init();
formRun.run();
formRun.wait();
}
................................................................................................................................................
/// <summary>
/// Adds the specified field to the grid control.
/// </summary>
/// <param name="tableId">
/// The <c>tableId</c> value that the field is on.
/// </param>
/// <param name="fieldId">
/// The ID of the field.
/// </param>
/// <param name="formBuildDataSource">
/// The <c>FormBuildDataSource</c> on the form.
/// </param>
/// <param name="formBuildGridControl">
/// The grid control on the form.
/// </param>
/// <param name="allowControlEdit">
/// A Boolean value that specifies whether to allow editing of the control.
/// </param>
public void addField(tableId tableId,
fieldId fieldId,
FormBuildDataSource formBuildDataSource,
FormBuildGridControl formBuildGridControl,
boolean allowControlEdit)
{
FormBuildStringControl formBuildStringControl;
Object formBuildControl;
SysDictField dictField;
int j;
tableId rootTableId;
dictField = new SysDictField(tableId, fieldId);
if(dictField.isSystem())
{
//System fields are only stored on the root table, so get the information from there.
rootTableId = SysDictTable::getRootTable(tableId);
dictField = new SysDictField(rootTableId, fieldId);
}
if (dictField.saveContents())
{
for(j = 1;j <= dictField.arraySize(); j++)
{
if (dictField.baseType() == Types::String ||
dictField.baseType() == Types::RString ||
dictField.baseType() == Types::VarString)
{
formBuildStringControl = formBuildGridControl.addDataField(formBuildDataSource.id(), fieldId, j);
formBuildStringControl.displayHeightMode(0);
formBuildStringControl.displayHeightValue(1);
formBuildStringControl.label(dictField.name());
formBuildStringControl.helpText(dictField.label());
formBuildStringControl.allowEdit(allowControlEdit);
}
else if(dictField.baseType() == Types::Int64)
{
// Reference Controls are created by default for surrogate foreign keys. However, the raw 64-bit
// integer should always be displayed. Force all Int64 type fields to use an Int64 Control.
formBuildControl = formBuildGridControl.addControl(FormControlType::Int64, dictField.name());
formBuildControl.datasource(formBuildDataSource.id());
formBuildControl.dataField(fieldId2Ext(fieldId,j));
formBuildControl.label(dictField.name());
formBuildControl.helpText(dictField.label());
formBuildControl.allowEdit(allowControlEdit);
}
else
{
if (dictField.baseType() != Types::Container)
{
formBuildControl = formBuildGridControl.addDataField(formBuildDataSource.id(), fieldId, j);
formBuildControl.label(dictField.name());
formBuildControl.helpText(dictField.label());
formBuildControl.allowEdit(allowControlEdit);
}
else
{
formBuildControl = formBuildGridControl.addControl(FormControlType::String,'TableBrowserContainer');
formBuildControl.datasource(formBuildDataSource.id());
formBuildControl.dataField(fieldId2Ext(fieldId,j));
formBuildControl.label(dictField.name());
formBuildControl.helpText(dictField.label());
formBuildControl.displayLengthMode(0);
formBuildControl.displayLengthValue(5);
formBuildControl.lookupButton(2);
}
}
}
}
}
public void clicked()
{
Form tableBrowser;
FormBuildDataSource formBuildDataSource;
FormBuildGridControl formBuildGridControl;
FormBuildDesign formBuildDesign;
DictTable dictTable;
FormRun formRun;
Args args;
Args browserArgs;
dictTable = new DictTable(tableNum(CustomTable));
browserArgs = new Args();
browserArgs.name(formstr(CustomForm));
formRun = classfactory.formRunClass(browserArgs);
tableBrowser = formRun.form();
formBuildDesign = tableBrowser.design();
super();
formBuildDataSource = form.dataSource(1);
formBuildGridControl = formBuildDesign.control('Grid');
formBuildGridControl.dataSource(dictTable.name());
formBuildGridControl.allowEdit(true);
element.addField(tableNum(CustomTable),fieldNum(CustomTable,Occupation),formBuildDataSource,formBuildGridControl,true );
args = new Args();
args.object(tableBrowser);
formRun = classfactory.formRunClass(args);
formRun.enableCountryRegion(false);
formRun.init();
formRun.run();
formRun.wait();
}
................................................................................................................................................
/// <summary>
/// Adds the specified field to the grid control.
/// </summary>
/// <param name="tableId">
/// The <c>tableId</c> value that the field is on.
/// </param>
/// <param name="fieldId">
/// The ID of the field.
/// </param>
/// <param name="formBuildDataSource">
/// The <c>FormBuildDataSource</c> on the form.
/// </param>
/// <param name="formBuildGridControl">
/// The grid control on the form.
/// </param>
/// <param name="allowControlEdit">
/// A Boolean value that specifies whether to allow editing of the control.
/// </param>
public void addField(tableId tableId,
fieldId fieldId,
FormBuildDataSource formBuildDataSource,
FormBuildGridControl formBuildGridControl,
boolean allowControlEdit)
{
FormBuildStringControl formBuildStringControl;
Object formBuildControl;
SysDictField dictField;
int j;
tableId rootTableId;
dictField = new SysDictField(tableId, fieldId);
if(dictField.isSystem())
{
//System fields are only stored on the root table, so get the information from there.
rootTableId = SysDictTable::getRootTable(tableId);
dictField = new SysDictField(rootTableId, fieldId);
}
if (dictField.saveContents())
{
for(j = 1;j <= dictField.arraySize(); j++)
{
if (dictField.baseType() == Types::String ||
dictField.baseType() == Types::RString ||
dictField.baseType() == Types::VarString)
{
formBuildStringControl = formBuildGridControl.addDataField(formBuildDataSource.id(), fieldId, j);
formBuildStringControl.displayHeightMode(0);
formBuildStringControl.displayHeightValue(1);
formBuildStringControl.label(dictField.name());
formBuildStringControl.helpText(dictField.label());
formBuildStringControl.allowEdit(allowControlEdit);
}
else if(dictField.baseType() == Types::Int64)
{
// Reference Controls are created by default for surrogate foreign keys. However, the raw 64-bit
// integer should always be displayed. Force all Int64 type fields to use an Int64 Control.
formBuildControl = formBuildGridControl.addControl(FormControlType::Int64, dictField.name());
formBuildControl.datasource(formBuildDataSource.id());
formBuildControl.dataField(fieldId2Ext(fieldId,j));
formBuildControl.label(dictField.name());
formBuildControl.helpText(dictField.label());
formBuildControl.allowEdit(allowControlEdit);
}
else
{
if (dictField.baseType() != Types::Container)
{
formBuildControl = formBuildGridControl.addDataField(formBuildDataSource.id(), fieldId, j);
formBuildControl.label(dictField.name());
formBuildControl.helpText(dictField.label());
formBuildControl.allowEdit(allowControlEdit);
}
else
{
formBuildControl = formBuildGridControl.addControl(FormControlType::String,'TableBrowserContainer');
formBuildControl.datasource(formBuildDataSource.id());
formBuildControl.dataField(fieldId2Ext(fieldId,j));
formBuildControl.label(dictField.name());
formBuildControl.helpText(dictField.label());
formBuildControl.displayLengthMode(0);
formBuildControl.displayLengthValue(5);
formBuildControl.lookupButton(2);
}
}
}
}
}
No comments:
Post a Comment