Wiki Home

Select On Entry


Namespace: Wiki
The fix proposed below no longer works in VFP9. To get select on entry to work with the first mouse click in VFP9, put this code in your gotfocus() event:

IF This.SelectOnEntry
  This.SetFocus()
  NODEFAULT
ENDIF



--
Derek Kalweit
There is one thing missing to make it work:

Make sure there is a "K" in the format property of the control.

Also, the following code will actually make this work when the textbox / spinner control is in a grid:

IF This.SelectOnEntry
  this.selstart = 1
  This.SetFocus
  NODEFAULT
ENDIF


Ben Creighton

This gem from Barbara Peisch in the Fox Forum:
You can get Select On Entry to work with the mouse by putting THIS.SETFOCUS() in the gotfocus method.
You can get the same effect (without the gotcha described below) using DODEFAULT() in Got Focus. I use this code in my base classes:
if This.SelectOnEntry
    dodefault()
endif This.SelectOnEntry
-- Doug Hennig
One minor gotcha to look for when doing this. If a form is launched from a Valid or When event (to gather other information for example), and there is a textbox on the form that has this tip in it, VFP will throw an error because of the Set Focus.

In the Got Focus event of the textbox, you could search the call stack to see if the Valid or When is there (or any other event that causes VFP a problem):
local llSetFocusFlag, lcProgram
llSetFocusFlag = .T.
for lxx = program(-1) to 1 step -1
   lcProgram = upper(program(lxx))   && Small change -- SB
   if ".WHEN" $ lcProgram ;
       or ".VALID" $ lcProgram then
       llSetFocusFlag = .F.
       exit
   endif
endfor
if llSetFocusFLag then
   THIS.SetFocus()
endif

Program() is very fast so I don't think this imposes too much of a performance hit. If it does, a limitation could be imposed on the number of prgrams it checks in the call stack (e.g. 5). -- Larry Miller
Unfortunately no one of these solutions work as expected in grid cells. And one more "problem" - there is no way to make "partial" selection on first entrance to the box - it will always select all the contents, while it may be better to select all text only if you just click in the box - not after click'n'drag. -- Igor Korolyov
Category VFP Control Properties
( Topic last updated: 2007.06.17 10:50:58 AM )