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!

Detect what a TextBox loses focus to.

Status
Not open for further replies.

bartmc

Programmer
Aug 9, 2005
9
US
Is there a way to detect what an object is losing focus to.
Here's my situation, i have these LostFocus() functions that i use to validate data in a TextBox, If the data is invalid, i just call tb.Focus() to not let them out of the box, now here's the problem, i have an abort button, that should just wipe all the data in the TextBoxes clear and let them start over. I dont want them to have to clear out the box that they are in before they can hit the abort button. So, is their a way to say (if im losing focus to the abort button, just clear
me out and start over?) or am i going at this the wrong way?

Bart
 
Losing focus is not the best way to check validation. It actually breaks a few GUI Fundamentals.

Normally, you would fill out your text boxes and use a submit or update button to apply the changes. If there are errors, you would tell the user at that point - not on the fly.

You may have a special case where you need to check validation on the fly. If this is the case, I would look into the "TextChanged" event in a textbox. If the text isn't changed, why do you want to validate it?

Can you give us a little more detail on why you are doing this on the fly validation?
 
At last count there were 120 text fields that they have to enter in I have some buttons on the top of the screen (ADD/UPDATE/DELETE/SAVE/QUERY/ABORT/PRINT/PROCESS).
I'm just making sure that they are putting dates in the corect format and that any code they reference has an entry in the Database.

This is a very fast paced data input screen, if i required them to fill out the entire form then hit save they would probably shoot me because on average id say they miskey at least 10 of the 120 TextBoxes. So im just validating that that particular textbox makes sense, when they hit the save button, i then make sure that the entire form of data gets along. This has proved to be a quite successful solution for us, and the users seem to like it better than the check after im done keying in everything method.

Another reason for this is that this program is going to run on a Windows CE based wireless terminal, i want the transition from our Curses based terminal application to be as smooth as possible so im making the app function/look as close to the old appliation as possible so that we dont have to totally retrain 19 different locations of employees. TextChanged might be a better idea, and also Validate may be another idea, i just dont know that much about it. I've been programming Unix for years, this is my first MSFT application ever.


Bart


 
YIKES! 120 text boxes?

At this point I have 2 suggestions which I think you might like.

1. Do your validation on the fly as you were planning. Try to use textchanged and/or validate to control the validation.

2. if your users have to type in a date something similar to 2005/02/28 - I would recommed creating a custom user control that automatically generates the date for them.

your control would basically look like this:

[ txtYear ] / [ txtMonth ] / [ txtDay ]

As year reaches 4 characters, automatically move to the month field. After 2 characters in the month field, move to the day field. Then override your ToString() method for the usercontrol to send back txtYear.Text + "/" + txtMonth.Text.... blah blah

This will save them entering the / character all the time. that's 3 less keystrokes per textbox. They will LOVE YOU for that.

As an added note, if the user presses the Backspace key once a textbox has 0 characters in it, go to the end of the previous textbox. So if they are deleting the last month character, jump back to the end of the year text.

Hope that gives you some ideas.
 
Already do all that. I had to write my own TabStop type stuff FOR Windows CE since .NET compact Framework doesnt have real good navigational tools especially for traversing pages and pages of textboxes on different tabpages on multiple forms, and we have Full Keyboard/number pads attached to these terminals. In additon to your suggestions I also have hot keys for the different types of DataTypes that the textboxes have if their in a date box. T (for today) automatically enters todays date N is now in time boxes, auto format $ values etc...
1031 will be 10/31/2005 etc.. I have tons of shortcuts. But my problems is, is how do i ignore all of this if they hit abort? I have probably spent the most time tuning the navigation system on this app, they dont even need a stylus anymore (except for capturing signatures) OR they can trow away the keyboard and use nothing but the sytlus (dont even need to use the On Screen Keyboard). Like I said this is a fast paced app and i need them cutting through the data as fast as possible.

Really what im thinking of doing is writing it so that the GotFocus() event will check the previous textbox that they
were in's data and set focus back to it if it fails or just abort if abort was clicked. It think that this is probably the best solution since im already keeping up with what textbox they were previously in. I just thought their might be some sort of sender.LosingFocusTo() function or something.

Bart


Bart
 
Where are your dates coming from? Are they from a printed report?

You might want to look at barcoding and barcode fonts. We have found this to be a very simple and fast way of doing data entry. It's also quite cheap.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top