Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Image in Grid
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP1
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01010217
Message ID:
01013684
Views:
16
As with most things, there are many ways to accomplish what you want. Cut-N-Paste the coded examples below into a prg file and run them from within VFP.

Example 1 - Uses DynamicCurrentControl and BindEvent to accomplish the goals
PUBLIC oform1

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

DEFINE CLASS form1 AS form

	DoCreate = .T.
	Caption = "Example 1 - Using DynamicCurrentControl"
	Name = "Form1"

	ADD OBJECT grid1 AS grid WITH ;
		Height = 228, ;
		Left = 12, ;
		Top = 12, ;
		Width = 348, ;
		Name = "Grid1"

	PROCEDURE Init
		*!* Create Some Sample Data
		CREATE CURSOR crsTemp (Field1 L)
		FOR lnCounter = 1 TO 100
			INSERT INTO crsTemp (Field1) VALUES ((INT((2) * RAND( ))) = 1)
		ENDFOR

		GO TOP IN "crsTemp"
		this.grid1.anchor = 15
		this.grid1.ColumnCount = this.grid1.ColumnCount + 1
		this.grid1.RecordSource = "crsTemp"
		this.grid1.RowHeight = 32

		WITH this.grid1.Columns(this.grid1.ColumnCount)
			.width = 32
			.header1.caption = ""
			.name = "NewColumn"
			.sparse = .F.
			.controlsource = "crsTemp.Field1"
			.addobject("Image1", "Image")
			Bindevent(.Image1, "Click", This, "ImageClickHandler")
			.Image1.Picture = HOME(4) + "icons\office\CRDFLE01.ICO"
			.Image1.visible = .T.
			.addobject("Image2", "Image")
			Bindevent(.Image2, "Click", This, "ImageClickHandler")
			.Image2.Picture = HOME(4) + "icons\office\CRDFLE04.ICO"
			.Image2.visible = .T.
			.removeobject("Text1") && We won't be needing the default textbox for this column
			.DynamicCurrentControl = [iif(crsTemp.Field1, "Image1", "Image2")]
		ENDWITH
	ENDPROC
	
	PROCEDURE ImageClickHandler
		MESSAGEBOX("You Clicked Me!")
	ENDPROC
	
ENDDEFINE
Example 2 - Uses an Image Class and BackStyle_Access to accomplish the goals
PUBLIC oform2

oform2=NEWOBJECT("form2")
oform2.Show

RETURN

DEFINE CLASS form2 AS form

	DoCreate = .T.
	Caption = "Exmaple 2 - Using Image Class and BackStyle_Access"
	Name = "Form2"

	ADD OBJECT grid1 AS grid WITH ;
		Height = 228, ;
		Left = 12, ;
		Top = 12, ;
		Width = 348, ;
		Name = "Grid1"

	PROCEDURE Init
		*!* Create Some Sample Data
		CREATE CURSOR crsTemp (Field1 L)
		FOR lnCounter = 1 TO 100
			INSERT INTO crsTemp (Field1) VALUES ((INT((2) * RAND( ))) = 1)
		ENDFOR

		GO TOP IN "crsTemp"
		this.grid1.anchor = 15
		this.grid1.ColumnCount = this.grid1.ColumnCount + 1
		this.grid1.RecordSource = "crsTemp"
		this.grid1.RowHeight = 32

		WITH this.grid1.Columns(this.grid1.ColumnCount)
			.width = 32
			.header1.caption = ""
			.name = "NewColumn"
			.sparse = .F.
			.controlsource = "crsTemp.Field1"
			.addobject("Image1", "LogicalImage")
			.Image1.visible = .T.
			.CurrentControl = "Image1"
			.removeobject("Text1") && We won't be needing the default textbox for this column
		ENDWITH
	ENDPROC
		
ENDDEFINE

DEFINE CLASS LogicalImage as Image
	FUNCTION BackStyle_Access
		LOCAL lcPicture
		lcPicture = HOME(4) + "icons\office\" + IIF(crsTemp.Field1, "CRDFLE01.ICO", "CRDFLE04.ICO")
		IF this.Picture != lcPicture
			This.picture = lcPicture
		ENDIF
		this.MousePointer = 0
		RETURN THIS.BackStyle
	ENDFUNC

	PROCEDURE Click
		MESSAGEBOX("You Clicked Me!")
	ENDPROC
ENDDEFINE
Previous
Reply
Map
View

Click here to load this message in the networking platform