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. http://weblogs.foxite.com/sandstorm36/2008/08/09/placing-various-images-on-a-grid/
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: http://sandstorm36.blogspot.com/2012/03/more-objects-inside-grid-cell.html
And here is the extended codes:
Public oForm
oForm = Createobject('myForm')
oForm.Show
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
Endproc
Procedure Grid1.Init
With This.column1 As Column
.AddObject('myImage','Image')
.CurrentControl = 'myImage'
.myImage.Visible = .T.
.DynamicFontBold = 'thisform.ShowPicture(this.column1.myImage,junk.empcode)'
.Width = 180
.Sparse = .F.
.ReadOnly=.T.
Endwith
Endproc
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)
This.Refresh()
Endproc
Procedure ShowPicture(ImageObject, empcode)
ImageObject.Picture = Addbs(This.ImgPath)+m.empcode+".gif"
Endproc
Enddefine
Very special thanks to Cetin Basoz!
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: http://sandstorm36.blogspot.com/2012/03/more-objects-inside-grid-cell.html
And here is the extended codes:
Public oForm
oForm = Createobject('myForm')
oForm.Show
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
Endproc
Procedure Grid1.Init
With This.column1 As Column
.AddObject('myImage','Image')
.CurrentControl = 'myImage'
.myImage.Visible = .T.
.DynamicFontBold = 'thisform.ShowPicture(this.column1.myImage,junk.empcode)'
.Width = 180
.Sparse = .F.
.ReadOnly=.T.
Endwith
Endproc
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)
This.Refresh()
Endproc
Procedure ShowPicture(ImageObject, empcode)
ImageObject.Picture = Addbs(This.ImgPath)+m.empcode+".gif"
Endproc
Enddefine
Very special thanks to Cetin Basoz!
Hi Jun.
ReplyDeleteCan you please email me at dhennig@stonefield.com? There is something I would like to discuss with you. Thanks.
Doug Hennig
Thank you Doug!
ReplyDelete