Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Position cursor in a EditBox in grid
Message
From
19/04/2019 09:00:52
 
 
To
18/04/2019 07:49:13
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01668156
Message ID:
01668201
Views:
98
Likes (2)
Jumping in, based on Rick's idea to emulate the repositioning of the cursor with the KEYBOARD command.

When the size of the edit box's value has increased during editing, .SelStart may not be properly set when losing focus. A workaround is to fetch the value only after user leaves the Grid, and not the EditBox.
CLEAR

_Screen.AddObject("other", "textbox")
_Screen.other.Visible = .T.

* prepare some data
CREATE CURSOR Source (Col Varchar(200))

INSERT INTO Source VALUES ("Some Text")
INSERT INTO Source VALUES ("Some more Text")
INSERT INTO Source VALUES ("")

GO TOP

LOCAL Test AS FRM

* instantiate a modeless form with a grid inside
m.Test = CREATEOBJECT("FRM")
m.Test.Show()

READ EVENTS

m.Test = .NULL.
_Screen.RemoveObject("other")

DEFINE CLASS FRM AS Form

	Top = 60
	Left = 120

	ADD OBJECT GRD AS Grid WITH ColumnCount = 1

	* closing the form will terminate the test
	PROCEDURE Destroy
		CLEAR EVENTS
	ENDPROC

	PROCEDURE GRD.Init

		This.RowHeight = 40

		This.RecordSource = "Source"

		WITH This.Columns(1) AS Column
			.AddObject("Editor", "EditBoxSP")
			.Editor.Visible = .T.
			.CurrentControl = "Editor"
			.RemoveObject("Text1")
			.Sparse = .F.
		ENDWITH

	ENDPROC

	* Grids don't have a LostFocus. Valid (which in fact should stand for BeforeLostFocus) is close enough, though.
	* We use it to signal that the user has quit editing the grid and he/she is going somewhere else.
	* When user remains inside the grid, the behavior is standard.
	* The reference to the control is hard-coded. In real life? It won't be, of course.
	PROCEDURE GRD.Valid
		IF This.ActiveColumn != 0 AND UPPER(This.Columns(This.ActiveColumn).CurrentControl) == "EDITOR"
			This.Columns(This.ActiveColumn).Editor.OutOfGridPosition = This.Columns(This.ActiveColumn).Editor.SelStart
		ENDIF
	ENDPROC

ENDDEFINE

DEFINE CLASS EditBoxSP AS EditBox

	OutOfGridPosition = -1

	PROCEDURE GotFocus
		* repositioning with the Keyboard is only done when the user is coming back to the grid, after his/her errands
		IF This.OutOfGridPosition != -1
			* from the start, as much as needed
			KEYBOARD '{HOME}'+REPLICATE('{RIGHTARROW}', This.OutOfGridPosition)
			This.OutOfGridPosition = -1
		ENDIF
	ENDPROC

ENDDEFINE
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform