Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grid Defaults to Table Layout
Message
From
19/12/2007 12:18:30
Dorin Vasilescu
ALL Trans Romania
Arad, Romania
 
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01276612
Message ID:
01276635
Views:
33
>Hi Gang!
>
>Strange problem here!
>
>I have a form with a grid (grdDetail)on it. It works well with a controlsource called REORDER.
>
>I wanted to add another grid (grdDetailManual) to the form (not visible at this point when run), with a controsource called REORDER2. It is a COPY of the original grid. (And the REORDER2 table has the same sturcture as the REORDER table. In fact, it was created from REORDER by using the COPY STRUCTURE to c:\temp\REORDER2 WITH CDX command.). I went in and changed the Recordsource of the grid and its columns to be REORDER2. It's job, when run later and visible, is to be a temporary holding place for order details, and then the data from this is transfered to the table REORDER.
>
>When, run, this new grid does not display the data as the original grid did. It displays the data in a default layout, like the fields are arranged in the table. In fact, the recordsource of each column is "NONE", now. If I go back and reassigned each column to REORDER.fieldname, it still changes back to "NONE" after saving the form.
>
>What am I totalling overlooking here??

When you change RecordSource for grid, this also reset ControlSource for all columns to None
The same at runtime.
The behavior is exactly what you've noticed.

Use this small prg to change grid's RecordSource in designer
procedure change_grd_source
LPARAMETERS tcNewRecordSource
LOCAL lnSelObjectCount, loGridRef, lnCnt
LOCAL ARRAY laSelectedObject[1], laColumnSources[1]
lnSelObjectCount = ASELOBJ(laSelectedObject)
IF lnSelObjectCount = 0
	WAIT WINDOW 'Select a grid in Form Designer first' nowait
	RETURN
ENDIF
loGridRef = laSelectedObject[1]
IF loGridRef.BaseClass # 'Grid'
	WAIT WINDOW 'One Grid object must be selected' nowait
	RETURN
ENDIF
IF loGridRef.ColumnCount>0
	DIMENSION laColumnSources[loGridRef.ColumnCount]
	FOR lnCnt = 1 TO loGridRef.ColumnCount
		laColumnSources[lnCnt] = JUSTEXT(loGridRef.Columns(lnCnt).controlsource)
	NEXT
ENDIF
loGridRef.RecordSource = tcNewRecordSource
FOR lnCnt = 1 TO loGridRef.ColumnCount
	IF !EMPTY(laColumnSources[lnCnt])
		loGridRef.Columns(lnCnt).ControlSource = tcNewRecordSource+'.'+laColumnSources[lnCnt]
		loGridRef.Columns(lnCnt).setall('ControlSource',tcNewRecordSource+'.'+laColumnSources[lnCnt])
	ENDIF
	
NEXT
Use this one to change columns/controls name like underlying RecordSource fields
procedure change_grd_columns

LOCAL lnSelObjectCount, loGridRef, lnCnt
LOCAL ARRAY laSelectedObject[1], laColumnSources[1]
lnSelObjectCount = ASELOBJ(laSelectedObject)
IF lnSelObjectCount = 0
	WAIT WINDOW 'Select a grid in Form Designer first' nowait
	RETURN
ENDIF
loGridRef = laSelectedObject[1]
IF loGridRef.BaseClass # 'Grid'
	WAIT WINDOW 'One Grid object must be selected' nowait
	RETURN
ENDIF

FOR lnCnt = 1 TO loGridRef.ColumnCount
	IF NOT EMPTY(loGridRef.Columns(lnCnt).ControlSource)
		loGridRef.Columns(lnCnt).Name = 'col'+PROPER(JUSTEXT(loGridRef.Columns(lnCnt).ControlSource))
		oControl = loGridRef.Columns(lnCnt).Controls(2)
		cPrefix = ICASE( oControl.BaseClass = 'Textbox','txt' ;
			, oControl.BaseClass = 'Combobox','cb' ;
			, oControl.BaseClass = 'Checkbox','chk' ;
			, oControl.BaseClass = 'Commandbutton', 'cmd' ;
			, oControl.BaseClass = 'Container', 'cnt' ;
			, oControl.BaseClass = 'Control', 'cnt' ;
			,'obj')
		loGridRef.Columns(lnCnt).Controls(1).Name = 'hd' + PROPER(JUSTEXT(loGridRef.Columns(lnCnt).ControlSource))
		loGridRef.Columns(lnCnt).Controls(2).Name = cPrefix+PROPER(JUSTEXT(loGridRef.Columns(lnCnt).ControlSource))
	ENDIF
NEXT
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform