Thursday, March 29, 2012

Various Images in a Grid - Part II

I have previously posted a way to show different images in a grid on Weblogs using 5 image objects and employing DynamicCurrentControl property of the grid.  That is because the need is limited only to that 5 images.

However, now that I need to really show varying undetermined number of images on a grid based on outside image files (jpegs) in a folder, that approach is a no no.  Therefore I sought other ways shown by experts such as Cetin Basoz and checked how that can be implemented on my needs. 

Most of the codes are adapted from Cetin's especially the usage of DynamicFontBold, except that this approach gets the images straight on outside files in a folder.  The trick is to be able to link the record with the real file name of the image file via one field (or several combined fields).  And since mine has an asset number and the images are named after the asset number (by design), then it did not pose any problem.  Here is the result:

For creating several objects inside a grid cell, read this:

And here is the extended codes:

Public oForm
oForm = Createobject('myForm')

Define Class myForm As Form
    Height = 580
    Width = 600
    AutoCenter = .T.
    Caption = 'Various Images on Grid - Part II'
    ImgPath = _samples+"data\Graphics"
    Add Object Grid1 As Grid WITH ;
        Height = 570, Width = 590, RecordSource="junk",;
        ColumnCount=3, DeleteMark = .F., RowHeight = 180

    Procedure Load
    Set Talk Off
    Set Safety Off

    Select Left(last_name,4)+Left(first_name,4) As empcode, first_name, last_name  From (_samples+"data\employee") ;
        INTO Cursor junk NOFILTER

    Procedure Grid1.Init
    With This.column1 As Column
        .CurrentControl = 'myImage'
        .myImage.Visible = .T.
        .DynamicFontBold = 'thisform.ShowPicture(this.column1.myImage,junk.empcode)'
        .Width = 180
        .Sparse = .F.

    Procedure Grid1.AfterRowColChange
    Lparameters nColIndex
    * Because this involves getting actual outside images, 
    *grid is not properly refreshed sometimes so force refresh
    *here if you like (optional)

    Procedure ShowPicture(ImageObject, empcode)
    ImageObject.Picture = Addbs(This.ImgPath)+m.empcode+".gif" 

Very special thanks to Cetin Basoz!


  1. Hi Jun.

    Can you please email me at There is something I would like to discuss with you. Thanks.

    Doug Hennig