Solved

Dialog Form Behavior question

Posted on 2010-09-13
20
530 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 4
  • +4
20 Comments
 
LVL 29

Expert Comment

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

Accepted Solution

by:
shadow77 earned 125 total points
ID: 33668539
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
ID: 33669017
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Assisted Solution

by:Gururaj Badam
Gururaj Badam earned 125 total points
ID: 33669367
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
ID: 33670973
Probably you are closing frmData (the  caller) & frmContact instances together.
0
 
LVL 12

Assisted Solution

by:starlite551
starlite551 earned 125 total points
ID: 33671135
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
ID: 33671161
Main Form Designer.cs file
Form1.Designer.cs
0
 
LVL 12

Expert Comment

by:starlite551
ID: 33671179
DialogBox1.cs
DialogBox1.cs
0
 
LVL 8

Expert Comment

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

Expert Comment

by:starlite551
ID: 33671198
DialogBox1 Designer.cs
DialogBox1.Designer.cs
0
 
LVL 12

Expert Comment

by:starlite551
ID: 33671215
DialogBox2.cs
DialogBox2.cs
0
 
LVL 12

Expert Comment

by:starlite551
ID: 33671269
DialogBox2 Designer.cs
DialogBox2.Designer.cs
0
 
LVL 12

Expert Comment

by:starlite551
ID: 33671407
Complete Project Zip File..
DialogsDemo.zip
0
 
LVL 12

Expert Comment

by:starlite551
ID: 33671448
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
ID: 33671646
It's not closing. It's all working well with your code
0
 
LVL 1

Author Comment

by:Miles Thornton
ID: 33672650
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
ID: 33674285
@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
ID: 33674312
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
ID: 33674416
@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
ID: 33675123
Out of time, gotta go with a workaround
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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