Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 535
  • Last Modified:

Dialog Form Behavior question

I have a winforms app (VS2010, .Net 4, on Windows 7 64-bit - if that matters) in which I have a main form (frmMain) that calls a FixedDialog form (frmData) to gather information. frmData has to call another FixedDialog form (frmContact) for additional data. I need to use frmData.ShowDialog() to have a result to use to control the forms refresh behavior:
            frmContact contact = new frmContact(true);
            DialogResult dr = contact.ShowDialog();
            if (dr != System.Windows.Forms.DialogResult.Cancel) {...}
 
My problem is that when I close frmContact, frmData (the caller) also closes - I don't want frmData to close - the user very likely isn't done with the data entry.

How do I manage to get frmData to NOT close when frmContactData closes?

0
Miles Thornton
Asked:
Miles Thornton
  • 8
  • 4
  • 4
  • +4
4 Solutions
 
Gautham JanardhanCommented:
ideally it should not close..can you post your code please.
0
 
shadow77Commented:
Is the AcceptButton property for your form set to the button that the user clicks to activate the contact form?

If it is, then when the associated event handler finishes with the code above and exits, that will close your data dialog.  You need to assign the data form's OK (or Done) button to the AcceptButton property.
0
 
MathiyazhaganCommented:
Normally , A dialog window closes when you are assigning DialogResult property by your code/assinging this property to Button; and when closing dialog with Close (X) button (it will assign DislaogResult.Cancel). so, check your buttons' DialogResult property; they should be "None".it should be handeled in your code.for example

in frmData ,

private void btnShow_click(object sender,EventArgs e)
{
       using(  frmContact obj = new frmContact())
       {
                if(    obj.ShowDialog() == DialogResult.OK)
               {
                   obj.GetData();//do ur work here
               }
       }
       //DialogResult = DialogResult.OK; //don't assign dialog reslut here
}
private void btnClose_click(object sender,EventArgs e)
{
  DialogResult = DialogResult.Cancel;
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Gururaj BadamCommented:
A full length code will be very useful. But I suggest you to add frmData.Closing handler and put a breakpoint to study the Calling stacktrace to see what's making your frmData form to close.
0
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
Probably you are closing frmData (the  caller) & frmContact instances together.
0
 
starlite551Commented:
I have made a project which you can download.. May be this will help you and solve your problem I hope.. I have basically cascaded two dialogboxes customly created by me. first lets you choose a color and it has a button to choose size. On clicking that button dialog2 pops up and you can select a size and click on OK button. Then you come back to the first Dialogbox where you can again click on OK and You`ll notice that the Main Form has made changes accordingly in Size as well as Color. I think you were looking for such kind of code..
Form1.cs
0
 
starlite551Commented:
Main Form Designer.cs file
Form1.Designer.cs
0
 
starlite551Commented:
DialogBox1.cs
DialogBox1.cs
0
 
Gururaj BadamCommented:
zip the whole solution and upload. That will be easier rather giving only files.
0
 
starlite551Commented:
DialogBox1 Designer.cs
DialogBox1.Designer.cs
0
 
starlite551Commented:
DialogBox2.cs
DialogBox2.cs
0
 
starlite551Commented:
DialogBox2 Designer.cs
DialogBox2.Designer.cs
0
 
starlite551Commented:
Complete Project Zip File..
DialogsDemo.zip
0
 
starlite551Commented:
Create an Windows Forms project in Visual Studio then in solution explorer right click on solution and click on Add Existing Files then Add all the files in the zip file to it.. build the solution and run it..
0
 
Gururaj BadamCommented:
It's not closing. It's all working well with your code
0
 
Miles ThorntonSenior C# Developer and TFS AdministratorAuthor Commented:
Thank you so much for all the advice and the example! I am exploring Starlight551's project now. I am posting my project (zipped) for you to explore - Wow, what a pain! I have had to remove a lot of the files b/c their extensions are not allowed; I finally settled for just the forms and their .cs files...

Please be advised that I am using Nevron controls so if you don't have their library, most of the editing controls won't render and the solution won't compile as-is.

As near as I can tell The problem child is found at: NovaTech.Business.Admin.GUI.frmMain.tsbtnAddNewItemJobNumber_Click(object sender, EventArgs e) {}  I also started considering with using frmJob.Show() with a file-system flag file to trigger a refresh... A sub-optimal solution at best.
justTheForms.zip
0
 
Miles ThorntonSenior C# Developer and TFS AdministratorAuthor Commented:
@Shadow77: You asked: "Is the AcceptButton property for your form set to the button that the user clicks to activate the contact form?" - No, the AcceptButton property of each form is set to that form's OK button, and the sub-form activation is a different button. So... Thanks, but that's not it at all.
0
 
Gururaj BadamCommented:
I downloaded individual files, Create new empty solution, added project and files

I don't see any issue with your code. Verify once again or follow the above suite.
0
 
Miles ThorntonSenior C# Developer and TFS AdministratorAuthor Commented:
@Mathiyazhagan: I checked into what you said and even configured that way; both forms close.

It's odd; if I use .Show() in the main form and .ShowDialog() in the second form, then the behavior of the forms is what I want; I just don't get why .ShowDialog() doesn't work.

I am out of time; I'm going to have to find an alternative way to determine the result of the second form's closing at runtime.

Thank you everyone for your time and efforts! I really do appreciate it!
0
 
Miles ThorntonSenior C# Developer and TFS AdministratorAuthor Commented:
Out of time, gotta go with a workaround
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 4
  • 4
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now