PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms Is this a MS bug: Validate event does not set e,Cancel to true of TopLevelForm

Reply

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

 
Thread Tools Rate Thread
Old 10-02-2006, 06:16 AM   #1
sunil@volcanomail.com
Guest
 
Posts: n/a
Default Is this a MS bug: Validate event does not set e,Cancel to true of TopLevelForm


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

  Reply With Quote
Old 17-02-2006, 04:05 AM   #2
sunil@volcanomail.com
Guest
 
Posts: n/a
Default Re: Is this a MS bug: Validate event does not set e,Cancel to true of TopLevelForm

Does anyone haev any views about this? Please help...

Thanks & regards
Sunil

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off