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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Focus after a button is pressed?

Status
Not open for further replies.

DJVisuaL

Programmer
May 31, 2000
52
US
Simple question with a simple answer (I hope)
but I cant seem to find out how to do it...
...
I have a form with a few text boxes and buttons
I want the user to be able to tab through the text boxes
but NOT through any of the buttons
so I set the TabStop property on all of the buttons
...
the first textbox is for a folder path (ex. c:\hey\cool\)
next to this textbox is a Browse button that will place the
folder picked (using GETDIR()) into the textbox
after the browse button is another textbox for a description
I want the focus to goto the description textbox after the browse button is pressed
but instead it goes to the first textbox that has the path
ex.
the form opens
tab order/focus is on the first textbox for typing a path
user presses browse button and picks a folder instead of typing a path manually
GETDIR() returns and since the browse button has no tab
control goes back to the first textbox
now the user has to tab again to get to the description textbox
so it would be faster/better if the focus could go straight to the description textbox (tab order 2) after the browse button finishes..
...
any help is appreciated!
...
I use VFP 6.0
Thanks
 
DJVisuaL

Assuming I understand your problem correctly, at the end of code after the GETDIR() routine, put:-

THISFORM.txtTEXBOX1.SetFocus()

where the textbox is the description textbox.

Chris :)
 
I can .SetFocus of the description textbox from a button that is in the tab order.. but it wont let me set the focus from the browse button (which is not in the tab order aka tab stop)
...
Ive tried to put it before and after the GETDIR() call...
 
Hi DJVisual,

In the BrowseButtonClickEvent...

YOu have the code TO DO THE browse

Now in its LOSTFOCUSevent.. put the code

ThisForm.txtBox2.Value = myChosenValue
ThisForm.TxtBox2.SetFocus()
** txtBox2 is the name of the description text box.

I assume that you dont have the value set for the txtBox2 and probably, the value is with width 0(zero) and so the foxus is not staying on that.

Hope this solves your problem. :) ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
DJVisuaL

The fact that the browse button has TabStop = .F. will not prevent your browse button code from setting focus to a textbox.

You can set focus to a textbox irrespective of whether or not the textbox has a value.

You can even replace the textbox value with a value that is not of the same data type as the .ControlSource of the textbox, (it will revert when you tab into it or send error messages if you try a TABLEUPDATE()).

So the lack of a texboxt value is an irrelevance and not your problem either.

FWIW, I would build a new form using new controls, testing as you go, until you find, (if you ever do), what was causing the problem.

Chris :)
 
I tryed ramani's suggestion but it did not work...

I think I know what is happening tho
the GETDIR() function calls up the directory select dialog..
upon returning to the form .. the form's activate event comes and sets the focus back to the first in the tab order? maybe..but that should all happen first and then the next line of code in the browse button click event ?

I take out the GETDIR() call and it works... the description control gets focus.. but of course the whole point of the browse button is to get a folder so I cant keep it this way :)

also these controls are in a page frame if that makes any difference? Ive now changed the second control to a combo box but the result is the same...

here is my exact code

buttonBrowse.Click
THISFORM.pageCat.pageframeAdd.textboxFolder.Value = GETDIR('c:\','Pick a Folder!')
THISFORM.pageCat.pageframeAdd.comboboxDescription.SetFocus

buttonBrowse.TabStop = .F.
textboxFolder.TabIndex = 1
textboxFolder.TabStop = .T.
comboboxDescription.TabIndex = 2
comboboxDescription.TabStop = .T.
 
DJVisuaL

buttonBrowse.Click
THISFORM.pageCat.pageframeAdd.textboxFolder.Value = GETDIR('c:\','Pick a Folder!')
WAIT WIND [Where are we?]
THISFORM.pageCat.pageframeAdd.comboboxDescription.SetFocus()

buttonBrowse.TabStop = .F.
textboxFolder.TabIndex = 1
textboxFolder.TabStop = .T.
comboboxDescription.TabIndex = 2
comboboxDescription.TabStop = .T.

You could try inserting a
WAIT WIND as above - if it doesn't show, you will know that by setting focus to the first control on returning from GETDIR(), you are not executing the rest of the code.

If so, modify the .Activate event of the page of the .Pageframe by firstly adding a new form property .lGetDir, and then in the code put:-

WITH THISFORM
[tab]IF .lgetDir
[tab][tab]THIS.comboboxDescription.SetFocus()
[tab]ENDI
[tab].lGetDir = .F.
ENDW

So what you then need is to move the code following the WAIT WIND to the .GotFocus() event of
.comboboxDescription and amend accordingly.

Also you need to add

THISFORM.lGetDir = .T.

before the line

THISFORM.pageCat.pageframeAdd.textboxFolder.Value = GETDIR('c:\','Pick a Folder!')

Chris :)
 
Would it help if you coded like this:

buttonBrowse.Click

WITH THISFORM.pageCat.pageframeAdd
.textboxFolder.Value = GETDIR('c:\','Pick a Folder!')
.pageframeAdd.comboboxDescription.SetFocus

.buttonBrowse.TabStop = .F.
.textboxFolder.TabIndex = 1
.textboxFolder.TabStop = .T.

*- What will happen if you leave out the following lines ??
.comboboxDescription.TabIndex = 2
.comboboxDescription.TabStop = .T.
ENDWITH


HTH,
Weedz (Wietze Veld)
My private project:Download the CrownBase source code !!
 
LoL
I looked in my activate event for the page of the pageframe
and found this.textboxFolder.setfocus()
took that out and it works now..
but now if I switch from page to page the focus doesnt get set to the first control when I come back..
it is on the pages caption (i guess so you can tab thru the pages on the pageframe?)

is there a way to get rid of that all together?
i tryed to set the page's tabstop to false
that kills the ability to tab between pages
but instead of setting the focus to the page's caption or to the first control there is no focus set at all..

I guess I will make a variable to keep the getdir status like in chris' suggestion
*shrugs*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top