Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Control a row in a grid based on other row
Message
From
15/05/2008 06:16:55
 
 
To
13/05/2008 16:30:59
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01316474
Message ID:
01317240
Views:
35
This message has been marked as the solution to the initial question of the thread.
>Mike
>
>I believe I am almost there. What I have is similar to what Naomi suggested. A row with ID, parent ID and digit for sorting purpose that can be used color indication(maybe).
>If the parent id and row id are the same then this is a parent row. The good thing I only have to deal with 1 level. If they asked for more than one level, it is time back for major design issue.
>
>What the grid look like?
>the left row will have minus sign (bold) for parent but blank for a child.
>The child will have different color (grey). nothing like Christmas tree.
>
>The child is read only if the parent is not selected. Did that in the When()
>
>If I only could change the row color to dark grey if the parent row was not flagged and back to light grey when flagged, I would call it a day.

To me, that sounds as if that feature can be handled in a .Dynamic* expression, e.g. by doing an IndexSeek().
This example is somewhat quick-and-dirty:
LOCAL oForm as Form
oForm = CREATEOBJECT('TestForm')
oForm.Show(1)
RETURN

DEFINE CLASS TestForm as Form
	CurrentValue = 0
	AutoCenter = .T.
	PROCEDURE Load
		CREATE CURSOR parent_ (pkParent C(10), test Int)
		CREATE CURSOR child_ (pkChild C(10), fkParent C(10), test Int)

		LOCAL lcKey
		lcKey = SYS(2015)
		INSERT INTO parent_ values (m.lcKey, 1)
		INSERT INTO child_ values (SYS(2015), m.lcKey, 11)
		INSERT INTO child_ values (SYS(2015), m.lcKey, 12)

		lcKey = SYS(2015)
		INSERT INTO parent_ values (m.lcKey, 2)
		INSERT INTO child_ values (SYS(2015), m.lcKey, 21)
		INSERT INTO child_ values (SYS(2015), m.lcKey, 22)

		SELECT .F. as selected__, ;
			PR.pkParent, ;
			'' as fkParent, ;
			PR.test, ;
			0 ;
			FROM parent_ PR ;
		union ;
		SELECT .F. as selected__, ;
			'', ;
			CH.fkParent, ;
			0, ;
			CH.test ;
			FROM child_ CH ;
			INTO CURSOR gridSource READWRITE
		INDEX ON (TRANSFORM(selected__)+pkParent) Tag x COLLATE 'machine'
		INDEX on pkParent DESCENDING TAG y COLLATE 'machine'
		GO TOP
	ENDPROC

	ADD OBJECT grdTest as Grid WITH ;
		Left = 10, Top = 10, ;
		Width = 350, Height = 220, ;
		Anchor = 15, ;
		RowSource = 'gridSource', ;
		ColumnCount = 5
	PROCEDURE grdTest.Init
		This.SetAll('DynamicForeColor','This.DynamicX()','Column')
		WITH This.Column1
			.AddObject('Check1','Checkbox')
			WITH .Check1
				.Caption = SPACE(0)
				.Visible = .T.
			ENDWITH
			.Sparse = .F.
			.DynamicCurrentControl = "IIF(EMPTY(pkParent),'Text1','Check1')"
		ENDWITH
		BINDEVENT(This.Column1.Check1,'Click',Thisform,'GridRefresh')
	ENDPROC
	PROCEDURE grdTest.Destroy
		UNBINDEVENTS(This.Column1.Check1)
	ENDPROC
	PROCEDURE grdTest.DynamicX
		LOCAL lnColor, lcValue
		lnColor = RGB(255,0,0)
		IF INDEXSEEK( TRANSFORM(selected__)+fkParent, .F., 'gridSource','x')
			lnColor = RGB(0,0,0)
		ENDIF
		RETURN m.lnColor
	ENDPROC
	PROCEDURE GridRefresh()
		This.grdTest.Refresh()
	ENDPROC
ENDDEFINE
hth
-Stefan
Previous
Reply
Map
View

Click here to load this message in the networking platform