Wednesday, January 22, 2014

Setup a manged control for drag and drop

In an earlier post I have made an example of to make a form with a drag 'n' drop enabled managed control.

Now, here is the initialization code to put a nice image in the control (which is a PictureBox control now), and set the transparency color of the control to the background color of, in this case, the tab page it is on:

private void initDropControl()
    Image                           resImg;
    System.Drawing.Image            img;
    System.Drawing.Color            backGroundColor;
    int                             colorR;
    int                             colorG;
    int                             colorB;
    System.Windows.Forms.PictureBox dropControl;

    // Get handle to the control
    dropControl = ManagedHostDropFile.control();

    // Setup event handlers for the control
    dropControl.add_DragDrop(new ManagedEventHandler(this, 'dropFile_DragDrop'));
    dropControl.add_DragEnter(new ManagedEventHandler(this, 'dropFile_DragEnter'));

    // Load the AX resource image
    resImg = new Image();

    // Get the tab page background color
    backGroundColor = System.Drawing.ColorTranslator::FromOle(TabPageLoadFile.backgroundColor());
    colorR = backGroundColor.get_R();
    colorG = backGroundColor.get_G();
    colorB = backGroundColor.get_B();

    // Set the transparancy color of the AX resource image to the tab page background color
    resImg.transparent(true, colorR, colorG, colorB);

    // Create an image object that the Windows Form control is able to load
    img = System.Drawing.Image::FromHbitmap(new System.IntPtr(resImg.exportBitmap()));

    // Add the image to the control

How to delete Label Files from AX 2012

Here are the steps to delete Label Files from AX 2012:

  • Create a new model. You could call it "LabelsBeGone".
  • Open the AOT and move the Label File(s) you want to get rid of to the new model.
  • Close AX and stop the AOS.
  • Use AXUtil to delete the new model.
  • Delete the label files from the server folder; C:\Program Files\Microsoft Dynamics AX\60\Server\...\bin\Application\Appl\Standard
  • Start the AOS.
  • Skip the upgrade wizard.

New book: Inside Microsoft Dynamics AX 2012 R3

I just saw this on Amazon:

"Fully updated for Microsoft Dynamics AX 2012 R3!

Dig into the architecture and internals of Microsoft Dynamics AX 2012 R3 - with firsthand insights from the team that designed and developed it. Deepen your knowledge of the underlying frameworks, components, and tools - and deliver custom ERP applications with the extensibility and performance your business needs.

Useful for Microsoft Dynamics AX solution developers at all levels, this guide will provide max benefit to those who understand OOP, relational database, and Transact-SQL concepts."

The book should be out in June, so there is your summer holiday reading.

Monday, January 20, 2014

Relations to field id's and the data export framework

In AX 2012 there is no guarantee that id's are the same between otherwise similar applications. So when you have a reference to a field id in your data, that reference may be broken when you import data again.

But it seems like the framework is able to handle this issue, if you just give it a helping hand.

Consider a table like this:

When trying to export this table, you will get a few errors:

What I need to do, is to add a field holding the id for table of the field id reference, and add both fields to a field group (allowing the framework to figure out that these two fields are related):

I can't find any documentation about this behavior. If you know of any, please comment. 

Thursday, January 9, 2014

Need to drag and drop files or text into AX 2012?

In AX versions before 2012, Microsoft shipped a small ActiveX component that you could add to forms in order to be able to drag files onto the form and get the filepath and name of the file.

That ActiveX is not distributed anymore. The feature can be replaced by using a managed control, and you can see examples of that in the forms SMMDocuments and SMMEncyclopedia.

Here is a small form with samples on how to catch files and text being dropped on a control: Download from SkyDrive