How to: Create an Image List for Controls

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

If you use a Tree or a ListView control in a form, you must generate an image list that is loaded when the form is opened and released when the form is closed.

You can also use an image list in a Window control if the control is bound to an integer database field. The control uses the value of the field as an index to the image to be used.

Images in the list must be registered in the resAppl macro (in the Macros node in the Application Object Tree (AOT)).

Tip

Open the tutorial_Resources form to view the images already registered in the resAppl macro.

Create an Image List

  1. Create a class that extends the ImageListAppl class.

  2. Name the class ImageListAppl _XXX.

    For example, ImageListAppl_Aot, ImageListAppl_Prod.

  3. Override the build method to add the images to the list. You must call super() before adding your own code. For example:

       void build()
        {
            super(); 
            this.Add(#ImageProduction);
            this.Add(#ImageItem);
            this.Add(#ImageBOM);
            this.Add(#ImageService);
            this.Add(#ImageSetUp);
            this.Add(#ImageProcess);
            this.Add(#ImageQty);
        }

Tip

To ascertain how image lists are used in the application, open the tutorial_formListControl and tutorial_formTreeControl forms, and then check the ImageListAppl_* application classes.

Example: Use an Image List in a Form

Wherever you use a Tree control or a ListView control in a form, make modifications that correspond to those in the following example. It uses the ImageListAppl_Prod image list.

    void classDeclaration()
    {
        #resAppl
        ImageListAppl_Prod   imageListAppl_Prod;
        FormTreeControl      tree;
        FormListControl      list;
    }
    void init()
    {
        tree = element.control(control::myTree);
        list = element.control(control::myList);
        imageListAppl_Prod = new ImageListAppl_Prod();
        tree.SetImageList(imageListAppl_Prod.ImageList());
        list.SetImageList(imageListAppl_Prod.ImageList());
    }
    void insertTreeItem(int parent, str name)
    {
        FormTreeItem   item = new FormTreeItem(
            name,
            imageListAppl_Prod.Image(#ImageProduction)   , 1);
        ;
        tree.AddItem(parent,   FormTreeAdd::Last, item)
    }
    void insertListItem(int parent, str name)
    {
        FormListItem item = new FormListItem(
            name, 
            imageListAppl_Prod.Image(#ImageProduction));
        ;
        list.AddItem(item);
    }

See also

Image Manipulation Classes

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.