30 Haziran 2015 Salı

Axapta - Show image at grid column

In the sample we will use RefRecId field; show OK image when filled, show Cancel image when empty. For this, we write a display method to the table (or table data source of course):

 display ImageRes dispIsOKImg(gzrForeSightOrderLines l)
   return l.RefRecId == 0 ? #ImageError : #Image_OK;

Add a Window control to grid. At this sample it's name is LineOK. Make AlignControl of control to No. Write display method's name (for this sample is dispIsOKImg) to DataMethod, write table name (gzrForeSightOrderLines for this sample) to Datasource. Write suitable values to Height and Width. I wrote 14 both of them. If your image is so big you make ImageMode value as  Size to fit.

You will see pictures periodically refresh when run the form. For prevent this effect, you have to load images at form init:

ClassDeclaration method:
ImageList                           imageList;

Init method:
imageList = new Imagelist(Imagelist::smalliconWidth(),Imagelist::smalliconHeight());
imagelist.add(new image(#Image_OK));
imagelist.add(new image(#ImageError));

change return line like this at the Display method:

return l.RefRecId == 0 ? 1 : 0;

To see/update image list at resAppl macro:


To see all image resources at the system Tools->Development tools-> Embedded resources.