Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Textbox validating (like in VFP)?
Message
From
11/07/2008 12:57:49
 
 
To
11/07/2008 09:45:07
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01330520
Message ID:
01330607
Views:
22
>So how do I run a valid() method on a textbox as the user tries to tab out of it?
>
>For instance, on one form I built over in my VFP app, when the users enters a material line item on the PO entry form, they charge each material item to a Job. They just type in the Job No. Well, I always do a valid() method on the Job No in the textbox.valid() to make sure the Job is still open, and that it is really a good Job No, and I throw up a messge right then to tell them if it is invalid, and I do not let them tab out of the textbox.
>
>
>So how do I model this in my WPF textbox?

I'm implementing my error checking in my BO, I extend the ORM partial class with IDataErrorInfo. I've also been trying to avoid the lock them in the field till they get the answer right type of error checking.

However there are times you would need to do this so I would probably implement it in a PreviewLostKeyboardFocus event.

You may need to use the Dispatcher to force the focus back to your control:
        Keyboard.Focus(fi);
        FocusManager.SetFocusedElement(FocusManager.GetFocusScope(fi), fi);
        if (!fi.Focus()) 
          { 
          fi.Dispatcher.BeginInvoke(DispatcherPriority.Input, 
                                    new ThreadStart(delegate() {
                                      Keyboard.Focus(fi);
                                      FocusManager.SetFocusedElement(
                                        FocusManager.GetFocusScope(fi), fi);
                                      fi.Focus(); 
                                      })); 
          }
I'm showing a bunch of different ways to move focus in there you probably only need to use one of them.
Previous
Reply
Map
View

Click here to load this message in the networking platform