Thursday 2 October 2014

Display Images In A Grid



  • Step 1 - Declare global variables in <yourform>.classdeclaration
public class FormRun extends ObjectRun
{
    Imagelist imageList;
    Image image;
}
  • Step 2 - Create Image List in <yourForm>.init
public void init()
{
    imageList = new ImageList(ImageList::smallIconWidth(), ImageList::smallIconHeight());
    image = new Image();
    image.loadResource(1030);  // tick icon
    imagelist.add(image);
    image.loadResource(927); // info icon
    imageList.add(image);
    image.loadResource(928); // warning icon
    imageList.add(image);
    image.loadResource(929); // red x icon
    imageList.add(image);

    super();
    
}

  • Step 3 - Create a window field on the grid
Set the AutoDeclaration of the window field to yes in the properties dialog
Load the image list to the window in <yourForm>.init after the super();

public void init()
{
    imageList = new ImageList(ImageList::smallIconWidth(), ImageList::smallIconHeight());
    image = new Image();
    image.loadResource(1030); 
    imagelist.add(image);
    image.loadResource(927);
    imageList.add(image);
    image.loadResource(928);
    imageList.add(image);
    image.loadResource(929);
    imageList.add(image);

    super();
    <windowField>.imageList(imageList);
}

  • Step 4 - Create method to set image on window field
On the table that is driving the grid, add a display method to set the picture in the window field.
The picture set is the data item in the array, not the icon number

public client server display int setIcon()
{
    #define.TickIcon(0)
    #define.InfoIcon(1)
    #define.WarningIcon(2)
    #define.StopIcon(3)

    
    if(!InventTable::find(this.itemNumber))
    {
        return #StopIcon;
    }
    else if(this.qtyOnHand() <= 0)
    {
        return #WarningIcon;
    }

    return #TickIcon;
}


  • Step 5 - Link window field to data
On the properties of the window field to point to the data method in step 4

DataSource  = <table in step 4>
DataMethod = <display method in step 4>



No comments:

Post a Comment