Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Setfocus on first textbox control on page
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00944565
Message ID:
01034561
Views:
20
Hi Nick, Nadya and others

This is the code I use, it may not be the optimal code but it gets the job done. I had previously asked the same question and this code is based on a lot of feedback from the UT. If I am not mistaken Hilmar had a hand in getting this right for me, thanks. I also call this routine in my AfterNew(), AfterCancel() and AfterDelete() with parameter as .F., so please note you may have to modify it to works as per your framework.

form.Activate()
IF THIS.lActivateRunOnce
	THIS.lActivateRunOnce = .F.

	THIS.SetFocusToFirstControl(.T.)
ENDIF
form.SetFocusToFirstControl()
LPARAMETERS tlInit

#DEFINE CLASSLIST_DEF "CHECKBOX", "LISTBOX", "COMBOBOX", "COMMANDBUTTON", "OPTIONBUTTON", "SPINNER", "TEXTBOX", "EDITBOX", "GRID"

IF tlInit
	LOCAL lnLoop, lnClass, lnLoopPages, lnPagesControls, lcPageControlClass, lnPages


	WITH THISFORM
 		FOR lnLoop = .CONTROLCOUNT TO 1 STEP -1
			lcClass = UPPER(.CONTROLS[lnLoop].BASECLASS)

			IF INLIST(lcClass, CLASSLIST_DEF)
				THIS.oFirstControl = .CONTROLS[lnLoop]
			ELSE
				IF lcClass ="PAGEFRAME"
					lnPages = .CONTROLS[lnLoop].PAGECOUNT

*!*						FOR lnLoopPages = lnPages TO 1 STEP -1
						lnLoopPages = 1
						
 						FOR lnPagesControls = .CONTROLS[lnLoop].PAGES[lnLoopPages].CONTROLCOUNT TO 1 STEP -1
							lcPageControlClass = UPPER(.CONTROLS[lnLoop].PAGES[lnLoopPages].CONTROLS[lnPagesControls].BASECLASS)

							IF INLIST(lcPageControlClass, CLASSLIST_DEF)
								THIS.oFirstControl  = .CONTROLS[lnLoop].PAGES[lnLoopPages].CONTROLS[lnPagesControls]
							ENDIF
						ENDFOR
*!*						ENDFOR
				ENDIF
			ENDIF
		ENDFOR
	ENDWITH
ENDIF


THIS.pgf.ACTIVEPAGE = 1
THIS.oFirstControl.SETFOCUS()
Hope it helps. I also welcome suggestion if this code can be made to better perform or placed better in the classes/framework.
Regards
Bhavbhuti
___________________________________________
Softwares for Indian Businesses at:
http://venussoftop.tripod.com
___________________________________________
venussoftop@gmail.com
___________________________________________
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform