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

How to avoid cursor should not move to another control

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi

How can I avoid not to move the cursor to the next control until <Enter> key is pressed.
After getting help from text1 cursor moves to text2.

The code in lost focus event of the text1 is as follows:

Code:
            Do Form '\forms\finditem1'
            Select icfind
            This.Value = icode
            This.Parent.Parent.mbarcode.sstextbox1.Value = barcode
            This.Parent.Parent.mfull_desc.Value          = full_desc
            This.SetFocus && Focus must retain to Icode

text1 = Icode (Item Code)
text2 = BarCode (Barcode)

Thanks
 
Thanks for the reply,

It is already <ON> in load event of the form.

Saif
 
Saif,

Is this what you want to do:

1. If the user presses Enter, then move focus to the next control.

2. If the user uses some other means to move focus to another control (such as clicking with the mouse, or pressing Tab), then don't allow that.

Have I understood it right? If so, here is a possible solution:

1. Create a custom property of the control. Call it, say, llEnter.

2. In the control's Valid: [tt]RETURN THIS.llEnter[/tt]

3. In the control's GotFocus: [tt]THIS.llEnter = .F.[/tt]

4. In the contol's KeyPress:

[tt]LPARAMETERS nKeyCode, nShiftAltCtrl
THIS.llEnter = (nKeyCode = 13)[/tt]

I haven't tested that, but I think it should do what you want. If I've misunderstood the requirement, please clarify.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You COULD use the controls VALID method to test if the last key was ENTER and if not
fail the valid... you might want to allow ESCAPE

Code:
local m.retval
m.retval = .f.
if lastkey() <> 13
  m.retval = .t.
endif
return(m.retval)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
If you start another form, focus can't stay in any control of the current form. The focus is at one place in one form.

Besides that, to keep focus in a control, why not use the Valid event? Instead of This.Setfocus(), which isn't allowed in the Valid event, RETURN .F. to keep a focus, instead of RETURN .T., to not get a message you may RETURN 0, haven't tried. But anyway, if you start a new form that form gets active and focus.

Bye, Olaf.

 
Thanks for the reply!

I will check all these options, but before that I want ask (just for the information) what is the ideal environment for the following?

1. <TextBox> in which user input the Customer Code
2. Click on <Command Button> for Help to locate the particular Customer Code. After selecting the Cursor should focus to the textbox.
3. And, after pressing <Enter> the cursor should move to next control.

In my case, in lost focus event I put several checks whether the code is empty, or wrong code is entered and other customer related issues, so if I clicked on <command button> which contain the above mentioned code (which I transferred later from <command button Click> to lost focus event of the <textbox>), it performs all the checks sequentially which I don't want, I simply want the above mentioned points.

I hope I tried to convey what I need exactly!!

Thanks

Saif
 
I think you might want to ove some of the testing from LOSTFOCUS to VALID

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
How about setting the controlsources of the controls?

Then all you need in the Textbox Valid is:

Code:
IF LASTKEY()=13
   Return .T.
ELSE
   Do Form '\forms\finditem1'
   Thisform.Refresh() && instead of setting all the Value properties let controlsources do that via refresh
   Return 0
ENDIF

But if you have a command button and a textbox, shouldn't the command button click start the finditem1 form?

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top