validating a tab page

I have a tab page validating event to prevent the user from switching to other tab page if the current tab page has some required information not filled. When the validating fails, e.cancel is set to true. Now the problem starts. Any button or check box doesn't work anymore on that tab page. I mean button click event won't fire. The check box can't be checked and unchecked. The only thing that can be done is to enter information in the text field. Is this behavior by design If not, what can I do to make the button and check box work when the tab page validating fails

Thanks for any suggestions.



Answer this question

validating a tab page

  • Ben Taylor

    Have you tried explicitly selecting the tab-page you which to stay on

    this.tabPage1.Select()


  • dbeau

    It doesn't seem to work for me. I can't check the check box or click the button on the tab page. But I can type in the text field. I wonder what kind of stuff does Microsoft do behind the scene of e.Cancel = true.
  • DamsDev2007

    You know what I find. The reason why it's not working for me is because I use MessageBox.Show() to pop up a warning message when the validating fails. If I don't use MessageBox.Show(), everything works just fine. Is there any reason why I can't use MessageBox.Show() I really need to pop up the message because otherwise the user would wonder why they can't leave the tab page.
  • ryan.berry

    I see your point, louthy.

    However, if I put this.tabPage1.Select() after e.Cancel = true;

    The tab page validating event will be called twice and the user is finally able to switch to the other tab page. And the behavior afterward is weirdo.


  • kreigh

    Check this thread...


  • Joseph Wee

    Ok, did a bit of digging, and this worked for me:

    private void tabPage1_Validating(object sender, CancelEventArgs e)
    {
    ((TabPage)sender).Show();
    e.Cancel = true;
    }


  • Tom Z

    That's strange because I just created a standard WinForm app, added a tab-control with two tabs on.  On tab 1 I added a check-box.  I then set e.Cancel to be whatever the check-box is set to  in the validating event for tab-page 1.  So if it's ticked you can't move on, and if it's not then you can.  And it worked perfectly fine.

    Not very helpful to you I realise.  But maybe if you could create a quick test-app that does the same then maybe you can narrow it down a little.

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsApplication1
    {
     public partial class Form1 : Form
     {

      public Form1()
      {
       InitializeComponent();

      }

      private void tabPage1_Validating(object sender, CancelEventArgs e)
      {
       ((TabPage)sender).Show();
       e.Cancel = checkBox1.Checked;
      }
     }
    }


  • validating a tab page