none
Panel Validation on Modal Form RRS feed

  • Question

  • This issue revolves around the validating event of a panel.  Within an MDI environment, the validating event fires when another panel of the same form is selected and also when another MDI child form or its panels are selected.  This behavior is as expected.

    However, if I create a modal form which is not a child of the MDI form, the validating event of the
    panel will not fire when the MDI form or any of the child forms are selected.  The validating event
    will fire if another panel within the modal form is selected.

    We need the validating event of the panel in the modal form to fire once the MDI form or children forms are selected.  The Deactivated event of the modal form is not an option.  Is there anything suggestions?

    Wednesday, October 10, 2012 5:25 PM

Answers

  • Hi TurDB,

    I have a question about the third scenario. A modal form must be closed or hidden before you can continue working with the rest of the application. How can you change focus to the mdi form?

    Did you use show or showDialog method to display the "modal" form? I suggest  you to read this msdn document.

    Anyway, Control.Validating Event fired when the focus in the form changed. However, in the third scenario, the "modal" form is a different form which has its own focus. When you select other form, the focus of the "modal" form is not changed. That's why the Validating Event not fired.

    You can change the activecontrol of the "modal" form in Form.Activated and Form.Deactivate Event handler.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, October 12, 2012 3:10 AM
    Moderator

All replies

  • Hi TurDB,

    According to my knowledge, panel control is not selectable, I think you mean select child control in panel here.

    However,a modal form or dialog box must be closed or hidden before you can continue working with the rest of the application. How can you select mdi child form when the modal form is opened?

    If it is a Modaless form, the validating event will fire if you select another panel within the Modaless form because the activecontrol of the Modaless form is changed. The validating event not fired when you select mdi form because the active control of main form is change but the activecontrol of  the Modaless form is not changed. The mdi form is treat as a control while  Modaless form is not.

    For more details about activecontrol  and validating event, see http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx.

    If there is anything unclear, please let me know. If I misunderstood you, please kindly clarify the issue.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, October 11, 2012 8:39 AM
    Moderator
  • You are right it has nothing to do with the selection in of itself.  However, the selection does cause a focus change which fires the validating event. 

    Let me describe 3 scenarios. 

    In one scenario, there is a panel with a Validating event in a form that is an MDI child.  The event will fire if focus changes to any control outside the panel even if the other control is on a different MDI Child.  This works as expected.

    In the second scenario, a modal form is shown outside of the MDI environment.  This form has a panel with a validating event.  When the panel loses focus to any control with in the modal form, the validating event fires.  This also works as expected.

    This third scenario is giving me issues.  Let's say the panel in scenario 2 has focus and we change focus to a control within the MDI environment.  The validating event DOES NOT fire.

    So, is there a way to detect that focus has left the modal panel?

    Thursday, October 11, 2012 4:40 PM
  • Hi TurDB,

    I have a question about the third scenario. A modal form must be closed or hidden before you can continue working with the rest of the application. How can you change focus to the mdi form?

    Did you use show or showDialog method to display the "modal" form? I suggest  you to read this msdn document.

    Anyway, Control.Validating Event fired when the focus in the form changed. However, in the third scenario, the "modal" form is a different form which has its own focus. When you select other form, the focus of the "modal" form is not changed. That's why the Validating Event not fired.

    You can change the activecontrol of the "modal" form in Form.Activated and Form.Deactivate Event handler.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, October 12, 2012 3:10 AM
    Moderator