In Axapta, How to add a button to a dialog and intercept the click event? Thanks
Asked
Active
Viewed 1.3k times
2 Answers
5
If you are outside the RunBaseBatch
Framework, you can do it the following way:
Note this way doesn't require a dummy menu item button either.
Dialog creation:
private void dialog()
{
Dialog dlg = new Dialog();
DialogGroup dlgGroup;
FormBuildGroupControl buttonGroup;
FormBuildButtonControl buttonControl;
dlgGroup = dlg.addGroup('ButtonGroup');
buttonGroup = dlg.formBuildDesign().control(dlgGroup.formBuildGroup().id());
buttonControl = buttonGroup.addControl(FormControlType::Button, 'A Button');
buttonControl.registerOverrideMethod(methodStr(FormButtonControl, clicked),
methodStr(MyClass, myClickedMethod),
this);
dlg.run();
}
Method for override click:
private void myClickedMethod(FormButtonControl _formButtonControl)
{
info('hello world');
}

Andrew
- 404
- 5
- 16
-
Hi @Andrew nice advice! – ulisses Dec 06 '17 at 10:28
4
Option 1;
This line is needed in dialog run()
element.controlMethodOverload(true);
The you can overload the click event;
public void MyButton_clicked()
{
//bla
}
Option 2;
Put your button action code in a separate class, and create a menu option, the add a menu item button to execute your code;
dialog.addMenuItemButton(MenuItemType::Action,"YourNewMenuItem");
Which you use depends upon what you are trying to achieve really.

AnthonyBlake
- 2,334
- 1
- 25
- 39