Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2006

Tip: Looking for answers? Try searching our database.

Is this a MS  bug: Validate event does not set e,Cancel to true of TopLevelForm

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sunil@volcanomail.com - 10 Feb 2006 06:16 GMT
Dear All,
   I am using .net 1.1 sp1. I have a use case where I have added a
Form into another Form. f.e.x.
I have a Form frmMainForm and another form frmDetails.

in constructor of frmMainForm I create frmDetails Form and set its
parent as frmMainForm.
frmDetails form contains a TextBox Control. I have hooked on to the
Validating event of the TextBox. If the value of the TextBox is 10 I
display a message box and set e.Cancel = true. When frmDetails form is
run as a standalone form and I close the form after setting the TextBox
value to 10, then it displays a message and the form does not close.
But when frmDetails form is added to frmMainForm and the same workflow
is done, then on closing frmMainForm the CancelEventArgs e.Cancel is
false as a result of which the form closes.
The Validate event is firing twice because in onClosing function of
frmDetails I am calling frmDetails.Close.
Question: Is this a MS bug? Why does the frmMainDetails onClosing
function recieve e.Cancel as false? It should be getting e.Cancel as
true.

frmDetails:
public frmDetails( )
{
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();
    //
    // TODO: Add any constructor code after InitializeComponent call
    //
    oFrmDetails.TopLevel = false;
    oFrmDetails.Parent = panel1;
    oFfrmDetails.Show();
}

protected  override  void OnClosing(CancelEventArgs e    )
{
    //here e.Cancel is false even if frmDetails.textBox1 validating
funtion fails
               if(!e.Cancel)
        oFrmDetails.Close();
    base.OnClosing(e);
}

myTextbox:
public class myTexBox: TextBox
{
    protected override void OnValidating(CancelEventArgs e)
    {
        if(Text == "10")
        {
            MessageBox.Show("Please enter right value");
            e.Cancel = true;
        }
        base.OnValidating(e);
    }

}

frmDetails:
public class frmDetails : System.Windows.Forms.Form
{
    private myTexBox textBox1;
}

protected  override  void OnClosing(CancelEventArgs e    )
{
    //If frmDetails is run as a standalone form then e.Cancel is true if
               // textBox1 Validating event fails
    base.OnClosing(e);
}

Please help...

Thanks & regards
Sunil
sunil@volcanomail.com - 17 Feb 2006 04:05 GMT
Does anyone haev any views about this? Please help...

Thanks & regards
Sunil

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.