Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

manipulating tab control

Status
Not open for further replies.

scklifasovskiy

Programmer
Nov 12, 2012
57
CA
Hi all,
I have a form with pageframe on it.
On a page I have a container with five controls in it, its a search engine.
User enters string in first control(textbox) and presses Enter or Tab and it goes to search. No matter of the result (Found or not) cursor goes to next control in the container according to tab setup.
What I want is that if search is succesfull -- cursor goes to a particular control on the page.
So for this case I put TabStop on the rest of the controls in a container and does go out....BUT it sets focus on a page.
How can I force it to go to the the control I want?
 
Yo just need to call the target contol's SetFocus method.

So, if you want the cursor to go to (for example) Command1, your code will be similar to this:

Code:
* Do the search
llResult = THISFORM.Search()

* Was it successful?
IF llResult
  * Move focus to command button
  THISFORM.PageFrame1.Page1.Command1.[b]SetFocus[/b]
ENDIF

Obviously, you will need to provide the correct path to Command1. In the above code, I have assumed the command button is on the first page of the pageframe, but you will need to adjust that accordingly.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Forget about solving that with TabStop and TAB only: TAB will always move to the NEXT available control and if the control you desire to set focus is before the current control in tab order, the focus is instead set on the next page, perhaps.

Please reread Mikes answer, it will help you set the focus in the code you also query the search result. There are just some situations SetFocus might not work:

VFP help said:
the SetFocus method is not supported in the When Event, Valid Event, RangeHigh Event and RangeLow Event events. However, you can include a RETURN Command with an object name (RETURN <ObjectName>) in these events to set the focus to another control.

So if you query the search result within the valid event of search textboxes, you can't SetFocus, but there is a workaround described.

Bye, Olaf.


 
A good place to issue the SetFocus would be in the LostFocus of the textbox that contains the search term. That way, focus will move to the correct place regardless of whether the user hits Enter or Tab, or even uses the mouse to click on another control.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Easiest and cleanest way is to have a button "Search Button"
Set it t be "Default" in the windows property

in the click event of the search button do this:

Thisform.SearchValues()

Add a method to form call it SearchValues (or whatever)

This it is easy in the searchvalues to do what you want.

Example:

Code:
oField = thisform.myPageFrame.Page1.txtcStr
lcStr = oField.value
if empty(lcStr)
   return .f.
endif

&& Or a SQL Select
select YourTable
set order to yourIndex
if seek(lcStr)
   Messagebox("Found.")
   Thisform.myPageframe.page2.txtcSomeOtherfield.setfocus()
   return .t.
else
   messagebo("Not found)
   oField.Setfocus()  && Back to same box
endif


Ez Logic
Michigan
 
I just read Mike W's post.. it is almost identical to the way i do it.

Ez Logic
Michigan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top