ManagedHost control in Dynamics AX 2012

Friends,

Today, I would like to give a quick overview and an example of new ManagedHost control that has been introduced in AX 2012.

The ManagedHost is a Microsoft Dynamics AX control that hosts a .NET control on a form Actually, you can add and use Windows Presentation Foundation (WPF) or managed form controls. This was not available in DAX 2009.

The ManagedHost supports access to the properties, methods, and events of the specified .NET control. To provide access to these members of the .NET control, the ManagedHost uses the CLR interop feature of X++. [msdn]

Let me explain with a real quick example.

Create a new form and add a new ManagedHost control as shown below

ManagedHost

From the control selectors, select System.Windows.Forms and Button control as shown below and click on Ok Button

controller

Actually, I am trying to add a .NET button control and will invoke the events of the control from AX.

Then, Right click on the ManagedHost control and chose Events

events

From the list of events, select the click event and click on Add button as shown below

clik

Once you do this, you will automatically find that in the ClassDeclaration the control object is created.

public class FormRun extends ObjectRun

{

    System.Windows.Forms.Button _ManagedHost_Control;

 

}

Also, init() method will have the following code with the eventHandler.

  • You use the properties of the .NET control to configure that control or to obtain information from the control. To set a property value, assign a value to the set_<property name> property of the .NET control. To retrieve a value from a .NET control, use the get_<property name> property of the .NET control. [msdn]

I have added one line of code to set the button text as shown below

settext

Init() method – code below

public void init()

{

    super();

    _ManagedHost_Control = ManagedHost.control();

    _ManagedHost_Control.add_Click(new ManagedEventHandler(this, ‘ManagedHost_Click’));

 

    _ManagedHost_Control.set_Text("Open customer table");

}

 

When the button is clicked, ManagedHost_Click method gets triggered and I am just opening the customer table in the clicked event

void ManagedHost_Click(System.Object sender, System.EventArgs e)

{

    ;

    new SysTableBrowser().run(tableNum(CustTable));

}

 

If we open the events again, you will see that click event is mapped to AX X++ method “ManagedHost_Click” as shown below [just for your reference]

COMEBACK

We are done, Now right click on the form and chose Open.

You will see that .NET Button control is on your form with text “Open customer table” a shown below

buttonn

 

Click on the button and you should see the custTable opening in the TableBrowser.

image

You can try with other controls like Grid Views, progress bars, Calendar pickers or any other controls from the controller list, but I was unable to access some of the events/methods of .net controls in AX when I tried some [Chart control, Combo Box] .

hmm..Exploring more…will post soon.

For more details : http://msdn.microsoft.com/en-us/library/gg864879.aspx

Have a good weekend!

Thanks,

Happy Dax6ng.

Sreenath

Advertisements

3 Responses to “ManagedHost control in Dynamics AX 2012”

  1. Howard Webb Says:

    Hi,

    Thanks for your informative blog post. I was wondering if you had got a managed control in a dialog box yet?

    Thanks
    -Howard Webb

  2. venkatesh Says:

    hi srinath, very nice explanation and everyone can understand easyly.

    thanks


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: