setting focus to control after validation

K

kelvin.koogan

I have a number of controls on a tab page. I want to validate them all
when the user tries to leave the tab. I then want to highlight the
first control which fails validation. How can I do this? I try setting
focus but something seems to set the focus back to the control which
had it before validation. Any ideas?

TIA,
KK
 
S

Sheng Jiang[MVP]

If you are using MFC, see MFC Library Reference TN026: DDX and DDV Routines
 
K

kelvin.koogan

If you are using MFC, see  MFC Library Reference TN026: DDX and DDV Routines

Thanks, but I'm not using MFC, that's why I posted in a dotnet forum.

KK
 
B

Ben Voigt [C++ MVP]

I have a number of controls on a tab page. I want to validate them all
when the user tries to leave the tab. I then want to highlight the
first control which fails validation. How can I do this? I try setting
focus but something seems to set the focus back to the control which
had it before validation. Any ideas?

What is the call stack when you change the focus? If it is in the middle of
processing a focus change event then something might indeed change the focus
afterward.

You could post a custom message to yourself and set the focus then, it will
be placed at the end of the message queue instead of setting the focus
synchronously. The .NET way of doing PostMessage to another thread is with
Control.BeginInvoke, I'm not sure how that would work on the same thread.
I'd use the real PostMessage just to be safe. Or for pure .NET, a winforms
timer could work too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top