Solved

Dialog Form Behavior question

Posted on 2010-09-13
20
526 Views
Last Modified: 2013-12-16
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
Comment
Question by:Miles Thornton
  • 8
  • 4
  • 4
  • +4
20 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
Comment Utility
ideally it should not close..can you post your code please.
0
 
LVL 9

Accepted Solution

by:
shadow77 earned 125 total points
Comment Utility
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
 
LVL 10

Assisted Solution

by:Mathiyazhagan
Mathiyazhagan earned 125 total points
Comment Utility
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
 
LVL 8

Assisted Solution

by:Gururaj Badam
Gururaj Badam earned 125 total points
Comment Utility
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
 
LVL 16

Expert Comment

by:Vikram Singh Saini
Comment Utility
Probably you are closing frmData (the  caller) & frmContact instances together.
0
 
LVL 12

Assisted Solution

by:starlite551
starlite551 earned 125 total points
Comment Utility
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
 
LVL 12

Expert Comment

by:starlite551
Comment Utility
Main Form Designer.cs file
Form1.Designer.cs
0
 
LVL 12

Expert Comment

by:starlite551
Comment Utility
DialogBox1.cs
DialogBox1.cs
0
 
LVL 8

Expert Comment

by:Gururaj Badam
Comment Utility
zip the whole solution and upload. That will be easier rather giving only files.
0
 
LVL 12

Expert Comment

by:starlite551
Comment Utility
DialogBox1 Designer.cs
DialogBox1.Designer.cs
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

Expert Comment

by:starlite551
Comment Utility
DialogBox2.cs
DialogBox2.cs
0
 
LVL 12

Expert Comment

by:starlite551
Comment Utility
DialogBox2 Designer.cs
DialogBox2.Designer.cs
0
 
LVL 12

Expert Comment

by:starlite551
Comment Utility
Complete Project Zip File..
DialogsDemo.zip
0
 
LVL 12

Expert Comment

by:starlite551
Comment Utility
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
 
LVL 8

Expert Comment

by:Gururaj Badam
Comment Utility
It's not closing. It's all working well with your code
0
 
LVL 1

Author Comment

by:Miles Thornton
Comment Utility
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
 
LVL 1

Author Comment

by:Miles Thornton
Comment Utility
@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
 
LVL 8

Expert Comment

by:Gururaj Badam
Comment Utility
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
 
LVL 1

Author Comment

by:Miles Thornton
Comment Utility
@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
 
LVL 1

Author Closing Comment

by:Miles Thornton
Comment Utility
Out of time, gotta go with a workaround
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now