0

I need to get buttons (Menu item button/ button) and their properties belongs to a Form

For example: "CustTrans" Form
I need all buttons belong or exist in this Form
Result: all buttons on a treeNode, organized by design

Question: How to get buttons exist in a Form

X++?

Here is an example of what i need, all the buttons belongs in the CustTrans Form, for example organized by their Form Action control

Here is an example of what i need, all the buttons belongs in the CustTrans Form, for example organized by their Form Action control

Adnane
  • 21
  • 6

1 Answers1

0

Please check code below as example and modify it for your needs

Form                myForm;    
FormBuildDesign     design;
FormBuildControl    control;
int                 cnt = 0;
Set                 buttonsSet = new Set(Types::Class);

void findButtons(FormBuildControl _buildControl) 
{
    FormBuildControl    buildControl;
    int                 i;
    ;

    if (_buildControl.controlCount() > 0)
    {            
        for (i = 1; i <= _buildControl.controlCount(); i++)
        {
            buildControl = _buildControl.controlNum(i);
            findButtons(buildControl);
        }   
    }
    else
    {
        if (classidget(_buildControl) == classnum(FormBuildButtonControl) ||
            classidget(_buildControl) == classnum(FormBuildCommandButtonControl) ||
            classidget(_buildControl) == classnum(FormBuildDropDialogButtonControl) ||
            classidget(_buildControl) == classnum(FormBuildMenuButtonControl) ||
            classidget(_buildControl) == classnum(FormBuildFunctionButtonControl))
        {
            buttonsSet.add(_buildControl);
        }
    }
}
;

myForm = formRun.form();
design = myForm.design();

for (cnt = 1; cnt <= design.controlCount(); cnt++)
{
    control = design.controlNum(cnt);
    findButtons(control);
}   

Code example to build tree control

TreeItemIdx         treeItemIdx;
TreeItemIdx         parentItemIdx;
ImageRes            imageRoot   = imageListAppl_Tutorial.image(#ImageFormButtonGroup);
ImageRes            imageRes    = imageListAppl_Tutorial.image(#ImageFormButton);

SetEnumerator       se;
FormBuildControl    buildControl;
;

formTreeControl.deleteAll();

parentItemIdx = SysFormTreeControl::addTreeItem(formTreeControl,
                                                'Buttons',
                                                FormTreeAdd::Root,
                                                'Data on Root',
                                                imageRoot,
                                                true);

SysFormTreeControl::setOverlayImage(formTreeControl, parentItemIdx, imageListAppl_Tutorial.image(#ImageOverlayRedLock));

se = _buttonsSet.getEnumerator();

while (se.moveNext())
{
    buildControl = se.current();

    treeItemIdx  = SysFormTreeControl::addTreeItem(formTreeControl,
                                                   buildControl.toString(),
                                                   parentItemIdx,
                                                   'Data on element 2',
                                                   imageRes,
                                                   false);
}

SysFormTreeControl::expandTree(formTreeControl, formTreeControl.getRoot(), 1);
Aliaksandr Maksimau
  • 2,251
  • 12
  • 21