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
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
![]() |
Is this a MS bug: Validate event does not set e,Cancel to true of TopLevelForm |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Does anyone haev any views about this? Please help...
Thanks & regards Sunil |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

