Improve company productivity with a Business Account.Sign Up

x
?
Solved

Dialog Form Behavior question

Posted on 2010-09-13
20
Medium Priority
?
537 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
ID: 33668289
ideally it should not close..can you post your code please.
0
 
LVL 9

Accepted Solution

by:
shadow77 earned 375 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 375 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 8

Assisted Solution

by:Gururaj Badam
Gururaj Badam earned 375 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 375 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Article by: Shaun
Tiling windows is a great way to see multiple applications at once. Windows Tiler is a tool that automatically tiles open application windows as the open and close.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…

606 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