Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
PROBLEM: Grid changes my currently selected area/alias
Message
From
16/03/2006 15:41:45
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
PROBLEM: Grid changes my currently selected area/alias
Miscellaneous
Thread ID:
01105063
Message ID:
01105063
Views:
79
Hi everyone,

Whenever a grid event fires the current alias is set to the grids recordsource until the grid loses focus.

How can I prevent the grid from changing the current alias?

I get the same problem under VFP 9 Service pack 1 and also under VFP 7.

The following code demonstrates the problem:
*** START OF GRID PROBLEM SAMPLE
CREATE CURSOR curTmp2 (cid C(5), cproduct C(25))

CREATE CURSOR curTmp1 (cid C(6), cname C(20))
INSERT INTO curTmp1 (cid, cname) VALUES ('000001', 'test')

oF1 = CREATEOBJECT('clsMyForm')
oF1.Width = 600
oF1.oCmd1.Height = 20

oF1.AddObject('oGrid', 'clsMyGrid')

oF1.oGrid.Recordsource = ''
oF1.oGrid.Recordsourcetype = 1
oF1.oGrid.Recordsource = 'curTmp1'
oF1.oGrid.Columncount = 2

oF1.oGrid.Visible = .T.
oF1.oGrid.Refresh()


SELECT curTmp2
oF1.Caption = "Starting with alias '" + ALIAS() + "'"

oF1.AddObject('oTimer', 'clsMyTimer')
oF1.oTimer.Interval = 500 && Once per half second
oF1.oTimer.Enabled = .T.

oF1.Show()

READ EVENTS

RETURN

DEFINE CLASS clsMyForm AS Form  
	ADD OBJECT oCmd1 AS CommandButton
	
	PROCEDURE QueryUnload
		CLEAR EVENTS
	ENDPROC
	
	PROCEDURE oCmd1.Click
		lcAlias = ALIAS()
		SELECT curTmp2
		MESSAGEBOX("The alias was '" + lcAlias + "' but is now forced to 'CURTMP2'")
	ENDPROC
	
ENDDEFINE


DEFINE CLASS clsMyGrid AS Grid
	Top = 30
	
ENDDEFINE

DEFINE CLASS clsMyTimer AS Timer
	Interval = 500  && Once per half second
	
	PROCEDURE Timer
		THISFORM.Caption = TIME() + " Current alias is '" + ALIAS() + "'.  It should be 'CURTMP2'"
	ENDPROC
	
ENDDEFINE
*** START OF GRID PROBLEM SAMPLE
The sample shows a form with a command button and a grid. The command button has the focus and the currently selected area is alias 'curTmp2'. The grid shows records from alias 'curTmp1' (recordsource = 'curTmp1' and recordsourcetype = 1).

As soon as I tab to the grid (or click on it) and the grid receives focus the current alias automaticly changes from 'curTmp2' to 'curTmp1'.

When I then press CTRL+TAB to move the focus out of the grid and back to the button the current alias automaticly reverts back to 'curTmp2'.

How can I prevent the grid from automaticly changing the current alias?

Thanks.
Next
Reply
Map
View

Click here to load this message in the networking platform