Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Building object name and calling it
Message
From
05/03/2017 17:45:52
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
04/03/2017 10:57:41
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01648762
Message ID:
01648796
Views:
56
I see the problem starts with this "and the simple answer is that you can't color individual cells of a grid depending on what the status of the underlying record is" :) But this information is incorrect. You can, not only, color each individual cell of a grid based on dynamic conditions but you can even go further and display different colors within a single cell.

Actually, I had sample codes and even an FAQ about it here in UT at least 15 years ago.

Seeing is believing, I prepared a simple sample for you which you can just save and run to see (colors are ugly but you should get the idea).
Public oForm
oForm = Createobject('sampleform')
oForm.Show()


Define Class SampleForm As Form
	Height=600
	Width=400
	Dimension aColors[16]
	Dimension aTitles[1]
	Dimension aCountries[1]

	Add Object myGrid As Grid With Height=600, Width=400, Anchor=15, RecordSource='employee', ColumnCount = 3,RowHeight=21*3

	Procedure Load
		Set Multilocks On
		Use (_samples+'data\employee')
		CursorSetProp("Buffering",5,'Employee')
	Endproc

	Procedure myGrid.Init
		This.Columns(1).ControlSource='employee.Emp_id'
		This.Columns(2).ControlSource='employee.Country'
		With This.Columns(3)
			.AddObject('DayJobs', 'MyObject')
			.CurrentControl = 'DayJobs'
			.Width = 200
			.Sparse = .F.
			.DynamicFontBold = '(thisform.SetMyObjectColor(employee.Country, employee.Title))'
			.DayJobs.Visible = .T.
		Endwith
	Endproc
	Procedure SetMyObjectColor(tcCountry, tcTitle)
		Local lnTitleColor, lnCountryColor
		lnTitleColor = This.aColors[ASCAN(this.aTitles, m.tcTitle, 1, -1, 1, 1+2+4+8)]
		lnCountryColor = This.aColors[ASCAN(this.aCountries, m.tcCountry, 1, -1, 1, 1+2+4+8)]
		With This.myGrid.Columns(3).DayJobs
			.txtTitle.BackColor = m.lnTitleColor
			.txtFirstName.BackColor = m.lnCountryColor
			.txtLastName.BackColor = m.lnCountryColor
		Endwith
		Return .T.
	Endproc

	Procedure Init
		Select Distinct Title From employee Into Array This.aTitles
		Select Distinct country From employee Into Array This.aCountries

		This.aColors[1] = 0x8080FF
		This.aColors[2] = 0x80FF80
		This.aColors[3] = 0x80FFFF
		This.aColors[4] = 0xFF80FF
		This.aColors[5] = 0xFFFF80
		This.aColors[6] = 0xFF4000
		This.aColors[7] = 0xFF00FF
		This.aColors[8] = 0x00FF00
		This.aColors[9] = 0x808000
		This.aColors[10] = 0x0000FF
		This.aColors[11] = 0xFF0000
		This.aColors[12] = 0x800080
		This.aColors[13] = 0x800000
		This.aColors[14] = 0x008000
		This.aColors[15] = 0x000080
		This.aColors[16] = 0xFFFFFF
	Endproc
Enddefine

Define Class MyObject As Container
	Width = 200
	Add Object txtTitle As TextBox     With Top= 2, Left=2, Width = 200, Margin=0, BorderStyle=0, ControlSource='employee.Title'
	Add Object txtFirstName As TextBox With Top=23, Left=2, Width = 200, Margin=0, BorderStyle=0, ControlSource='employee.First_Name'
	Add Object txtLastName As TextBox  With Top=44, Left=2, Width = 200, Margin=0, BorderStyle=0, ControlSource='employee.Last_Name'
Enddefine
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform