Using Managed Host Control in Microsoft Dynamics AX 2012


Managed host control in Microsoft Dynamics AX 2012 is used to host a .NET or WPF control on a Microsoft Dynamics AX form. It is used to enhance the usability of the application and provides users with a rich experience design.

The ability to add these controls on a form gives access to many features that are not natively supported by standard Microsoft Dynamics AX. In addition, customized controls can be created in .NET and used as a managed host control. The integration between Microsoft Dynamics AX and .NET controls is seamless and easy to implement. Managed host controls do not support Microsoft Silverlight controls, however, Silverlight controls can be used in the Enterprise portal.

Managed host control uses the CLR interop feature of X++ to access the properties, methods and events of a specified .NET or WPF control. CLR interop is used because it supports implicit conversion of many X++ data types into corresponding .NET CLR data types. For complex data types like collections, some conversion may have to be performed.


  1. Microsoft Dynamics AX 2012
  2. The assembly of the control to be used must be added as a reference in the Microsoft Dynamics AX references node (AOT à References) and the assembly must be installed on the computer where Microsoft Dynamics AX client is installed

Important Concepts

  1. Properties

    Properties are used to assign or retrieve the values that define the behavior of a control. Since Microsoft Dynamics AX does not supports properties, all the properties of a .NET control are converted into methods. To assign a property any value, set_<Property Name>() is used and to retrieve a property’s value, where get_<Property Name()> is used.

  2. Events

    Event refers to any activity or occurrence detected by the system in response to a user or a system action. Both X++ and .NET controls support events. To integrate the events of a .NET control in Microsoft Dynamics AX, event handlers are used. An event handler is a registered form method that gets called every time an event is raised by the system.

  3. To register a .NET control event on a managed host control, a reference of the managed H=host control is obtained from an instance of a .NET control. The instance of the .NET control contains methods with the name add_<Event Name>, which is used to register a .NET event handler in Microsoft Dynamics AX. Microsoft Dynamics AX contains a class ManagedEventHandler whose instance is passed to the add_<Event Name> method.

    To register a form method as an event handler, pass the instance of ManagedEventHandler class, which takes the form and name of the method as an input, to the event method of .NET control as a parameter. The necessary business logic is added to the form method, which gets called every time the .NET control raises the event. To unregister an event handler, use the remove_<Event Name> method of the .NET control.


As part of this tutorial, all customers will be listed in a .NET grid view control and the selected record of the grid will be shown in an infolog.


  1. First of all create a new form. Open AOT à Forms

  3. Right click on Forms and create a new Form ManagedHostDemo

  4. Navigate to the Design node of the form and add a ManagedHost control.

  5. The Managed control selector dialog will then open. On the dialog, the top grid lists all the assemblies that are referenced in Microsoft Dynamics AX. To reference a new assembly, the Add reference button is used. The below grid list all the controls available in the selected assembly
  6. Select System.Windows.Forms from the assembly list and DataGridView from the control list and press OK
  7. A new managed host control will be added. Rename the control to DataGridViewManagedHost

  9. Set the Height property to Column height and Width property to Column width of the control

  11. Since managed host control cannot be used directly to access the methods of a .NET control, the reference of the managed host control must be obtained in a global variable of the same type as .NET control so that different properties and methods can be accessed

  13. Open the Class declaration node and write the following code
    //declare a variable of datagridview type
    System.Windows.Forms.DataGridView dataGridView;

  15. Override the init method of the form and write the following code in it after the super() call
  16. //get the reference of the managed host control
    dataGridView = DataGridViewManagedHost.control();
    //set row header visible property to false
    //set columns to auto fill


  17. Override the run method of the form and write the following code
    public void run()
        System.Windows.Forms.DataGridViewColumnCollection   columnCollection;
        System.Windows.Forms.DataGridViewRowCollection      rowCollection;
        CustTable custTable;
        System.String[] strValues;
        //define the columns of the grid
        columnCollection = dataGridView.get_Columns();
        columnCollection.Add("CustomerAcount","Customer account");
        columnCollection.Add("CustomerName","Customer name");
        //fill the rows of the grid
        rowCollection = dataGridView.get_Rows();
        while select * from custTable
            strValues = new System.String[2]();
            strValues.set_Item(0, custTable.AccountNum);

  19. Now open the form by right clicking the form and select Open


  21. All the customers will be shown in the .NET grid view control

  23. Now an event will be registered that will show the selected record in an infolog

  25. Right click the DataGridViewManagedHost control and select Events

  27. The Events dialog is then opened. It lists all the events that are available for the control

  29. Select SelectionChanged event and click on Add button

  31. It will create a corresponding X++ method and will register the method as an event handler in the init method

  33. The name of the newly created method is shown in the X++ methods column. Press the Close button to close the form

  35. Navigate to the init method and verify that the method added above is registered as an event handler. Since SelectionChanged event was to be registered, it is accessed via add_SelectionChanged method of the .NET control. An instance of ManagedEventHandler class having form and method name as input is passed as a parameter to the method

  37. Now open the DataGridViewManagedHost_SelectionChanged method and write the following code in it
    void DataGridViewManagedHost_SelectionChanged(System.Object sender, System.EventArgs e)
        System.Windows.Forms.DataGridViewCell cell;
        System.Windows.Forms.DataGridViewRow row = dataGridView.get_CurrentRow();
        cell = dataGridView.get_Item(0,row.get_Index());    

  39. Open the form and select any row. The selected customer account will be shown in the infolog

March 5, 2015


Email [email protected] with any questions you have pertaining to this course.

New CPE Accredited Courses Now Available for Dynamics AX, GP, and NAVEARN CREDITS TODAY