Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set focus on first contrl
Message
From
26/07/1999 06:26:39
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
25/07/1999 20:31:03
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00245917
Message ID:
00245983
Views:
16
>>In following code I need to guarantee the focus goes to the first readable control. I don't know the Tabindex of the first control because depends of the form, and this code is inside class and not always the first control is readable or has the property tabindex.

>
>>
>>FOR EACH oCont IN Thisform.Controls
>>    IF oCont.Baseclass = 'Pageframe'
>>       FOR EACH Ctrl IN oCont.Page1.Controls
>>           IF PEMSTATUS(Ctrl,'TabIndex',5) = .T. AND ;
>>              PEMSTATUS(Ctrl,'Readonly',5) = .T. AND ;
>>              Ctrl.Readonly = .F.
>>              Ctrl.SetFocus()
>>              EXIT
>>           ENDIF
>>       ENDFOR
>>       EXIT
>>    ENDIF
>>ENDFOR
>>
>
>>What is happening is that instead the focus goes to the second control (tabindex=2) is going to third (tabindex=3). What is wrong?
>
>
>There is no guarantee that the contols are in tab order. If you keep a variable that holds the smallest tab order and don't accept any tab orders with a number greater than that one, that should work.
>

You may arrange the controls to be in tab order (download torder.prg - it will rearrange the controls to go with the tab order), but relying on instanciation order is not a healthy practice (as we have seen in this example). Actually, in my form class I have an equivalent code snippet, like this
#define c_mnogo 1e6
local tajje, oCtl
* initialize the variable to remember the minimal tabindex to an impossibly high value
tajje=c_mnogo
oNjega=.null.
for each oCtl in thisform.controls
	if PEMSTATUS(oCtl, "SetFocus",5 ) and type("oCtl.tabindex")="N" and oCtl.visible and oCtl.enabled
* check if it's the minimal value encountered, and if it is, create a reference to that control
		if oCtl.tabindex<tajje
			tajje=oCtl.tabindex
			oNjega=oCtl
		endif
	endif
endf
dodefault()
if tajje<c_mnogo
	oNjega.SetFocus
endif
I'm not checking for read-only, because, theoretically, the first control to receive focus may be read-only, and if it's a memo, the user should be able to read, copy, scroll etc, which is still possible if it's read only. There's also a case of a long string in a short textbox, where the user should be given a chance of horizontal scroll (how is it done with a mouse?). Besides, it says "readable", not "writable" at the beginning of the message.

p.s. Just saw Mike popping up with the same solution... except he uses 1e7 :)

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform