Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Images in Grid

Status
Not open for further replies.

EmmaLu

Programmer
Jul 16, 2004
38
US
Is there a way to add images to a grid? I have a table with these fields: includeimage, imagefilename. I want to display a grid with a check box in column1 and the image for each record in the column2. Then let the user check which images they want to use.

I know how to add a checkbox and image control to grid columns, but don't know how to display the actual image in column2 based on the imagefilename.

Is this possible, or is there another way to do this?

Thanks - Emma
 
Use the oleboundcontrol as opposed to the image control;

Code:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


	**************************************************
*-- Form:         form1 (c:\intelisys\grid_pics.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   06/07/09 10:53:00 PM
*
DEFINE CLASS form1 AS form


	Top = 0
	Left = 0
	Height = 276
	Width = 409
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 2, ;
		DeleteMark = .F., ;
		Height = 238, ;
		Left = 17, ;
		Panel = 1, ;
		RowHeight = 170, ;
		ScrollBars = 2, ;
		Top = 24, ;
		Width = 365, ;
		Name = "Grid1", ;
		Column1.Width = 101, ;
		Column1.Name = "Column1", ;
		Column2.CurrentControl = "Oleboundcontrol1", ;
		Column2.Width = 232, ;
		Column2.Sparse = .F., ;
		Column2.Name = "Column2"


	ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
		Caption = "Header1", ;
		Name = "Header1"


	ADD OBJECT form1.grid1.column1.text1 AS textbox WITH ;
		BorderStyle = 0, ;
		Margin = 0, ;
		ForeColor = RGB(0,0,0), ;
		BackColor = RGB(255,255,255), ;
		Name = "Text1"


	ADD OBJECT form1.grid1.column2.header1 AS header WITH ;
		Caption = "Header1", ;
		Name = "Header1"


	ADD OBJECT form1.grid1.column2.oleboundcontrol1 AS oleboundcontrol WITH ;
		Top = 31, ;
		Left = 33, ;
		Height = 100, ;
		Width = 100, ;
		Name = "Oleboundcontrol1"


	PROCEDURE Load
		If Select("employee") > 0
			Use In employee
		Endif
		Use Home()+"\samples\tastrade\data\employee.dbf"
		Set Order To Tag EMPLOYEE_I   && EMPLOYEE_ID
	ENDPROC


	PROCEDURE grid1.Init
		With This
			.RecordSource = "employee"
			.column1.ControlSource ="employee.last_name"
			.column2.ControlSource ="employee.photo"
			.Refresh
			Go Top
		Endwith
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
 
You don't neccessarily need the oleboundcontrol, though the main aspect wh it works is, that the oleboundcontrol has a means of binding something to it. An Image control does not have a controlsource.

What you can do is this:
Unfortunately the main thing is missing there (broken link, image not available) - what code to put int the backstyle_access method:

Code:
* change alias.picpath to match recordsource and the field containing the path to the picture.
If This.Picture <> Alltrim(alias.picpath)
   This.Picture = Alltrim(alias.picpath)
Endif
RETURN THIS.BackStyle

It's a little more effort than to use the oleboundcontrol,but I think it's more lightweight and worth the hassle, as the oleboundcontrol is of course more directed towards showing an ole object than just a picture.

Bye, Olaf.
 
Thanks that worked perfectly.
Emma
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top