stighy
stighy

Reputation: 7170

How to add a button to a dialog and create a method for the click event

In Axapta, How to add a button to a dialog and intercept the click event? Thanks

Upvotes: 4

Views: 14623

Answers (2)

Andrew
Andrew

Reputation: 444

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');
}

Upvotes: 5

AnthonyBlake
AnthonyBlake

Reputation: 2354

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.

Upvotes: 4

Related Questions