Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Workaround for a bug
Message
From
15/06/2001 10:20:28
 
 
To
14/06/2001 21:01:24
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00519598
Message ID:
00519938
Views:
11
>>>>I have only tested this code for the conditions in it. There may be other factors that prevent a control from receiving focus, like visible property.
>>local loMinControl
>>loMinControl = .null.
>>for each loControl in ThisForm.Controls
>>   if isnull(loMinControl)
>>      if upper(loControl.BaseClass) <> "GRID" and pemstatus(loControl, 'SetFocus', 5) and loControl.Enabled
>>         loMinControl = loControl
>>      endif
>>      loop
>>   endif
>>   if upper(loControl.BaseClass) <> "GRID" and pemstatus(loControl, 'SetFocus', 5) and loControl.Enabled
>>      if loControl.TabIndex < loMinControl.TabIndex
>>         loMinControl = loControl
>>      endif
>>   endif
>>endfor
>><b>thisForm.oMinControl = loMinControl</b>
>>
>>>
>>>That works.
>>
>>Or, you can add a property to your form. Run this code one time in form.init(), and when you need to setFocus you can issue thisForm.oMinControl.setFocus().
>
>This brings the idea of using a property to hold the field we would like to use as the first focus of the form. We could just maintain that field when building the form. However, we don't have to think about it if we do it here. >We just have to make sure the tab index is well set.

Currently, I store the name of the control that has the lowest tabIndex in a form property. The form base class does this when the form inits (by inspecting the tabIndexes). The form itself has a method called setFirstFocus(), which does the obvious.

Mark's method seems more elegant to me...storing an object reference itself instead of the name of the control. This avoids the need for macro substition or eval() in the setFirstFocus() method.

There are advantages to having this stored in a property. For example, I don't like it when a button keeps focus after someone clicks on it. Perhaps they just printed an invoice by clicking the 'Print' command button. I call thisForm.setFirstFocus() at the end of the cmdPrint.click(). It would be much better if I had a thisForm.setCurrentFocus(), but I haven't done that yet...
Steve Gibson
Previous
Reply
Map
View

Click here to load this message in the networking platform