Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set focus to a control after validation in .NET
    primarykey
    data
    text
    <p>I have a WinForm application with several input controls on a form. In the validation event handler (either <code>Validating</code> or <code>Validated</code>), I need to determine what control to activate next, based on the validated value.</p> <p>In Microsoft's documentation of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx" rel="noreferrer">Validating</a> event, it states:</p> <blockquote> <p>Caution</p> <p>Do not attempt to set focus from within the Enter, GotFocus, Leave, LostFocus, Validating, or Validated event handlers. Doing so can cause your application or the operating system to stop responding. For more information, see the WM_KILLFOCUS topic in the "Keyboard Input Reference" section, and the "Message Deadlocks" section of the "About Messages and Message Queues" topic in the MSDN library at http: // msdn.microsoft.com/library.</p> </blockquote> <p>There is an <code>ActiveControl</code> property for a Form class that allows setting the control that is to become active, and no restrictions are mentioned. I have not found any other solution after several hours of web searches.</p> <p>Is setting the <code>ActiveControl</code> property (instead of <code>Focus</code>) from my Validated event handler a safe way to positively activate the control I want? If not, are there any solutions?</p> <p>Because the .NET Compact Framework doesn't have the <code>ActiveControl</code> property, can anyone suggest a solution?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload