Dialog form closes when Cancel button is pressed

Posted on 2007-11-26
Last Modified: 2010-04-23
I am displaying a modal form which a user can edit information in text boxes. If they click the Cancel button I am doing a ds.tables(0).rejectchanges which appears to be firing a close-form event... why???
Also, it does not reset the value in the binded text box to the original value like other forms do. Why? I do a ds.tables(0).rows(0).canceledit and then ds.tables(0).rejectchanges and would expect the original value to re-appear in the text box but it does not.... why??

Question by:michouis
  • 3
  • 2
LVL 18

Expert Comment

ID: 20351992
When you look at the properties for the form you'll see a property named "CancelButton" that accepts a Button.  If you click the button set there then the form will close and return DialogResult.Cancel.  Clear that property and the form won't close anymore.

Author Comment

ID: 20352122
I do not have the Cancel button set as the CancelButton property for the form. I have a totally different button called ExitButton that is set to the CancelButton property of the form... so please try again.

LVL 18

Accepted Solution

jcoehoorn earned 500 total points
ID: 20352233
A dataset has absolutely nothing to do with a form staying open or closed.  

The AcceptButton property is similar to CancelButton, but returns DialogResult.Ok instead of DialogResult.Cancel.  The only way the form will close is if you click one of those buttons, click the X in the top right of the form, or call the form's .Close(), .Dispose(), or .Hide() methods.  

It might be possible for another program to somehow slip a WM_CLOSE or WM_TERMINATE message into the window's event loop, but the .Net framework will only do that via the methods I just described.

Author Comment

ID: 20352819
ok., I changed the DialogResult property to None on all 3 buttons, (Update, Cancel, Exit) and it now behaves normally.

As for the rejectchanges not resetting the value to original value... I removed the binding format of "C"urrency from these text boxes and it also now behaves normally, just no currency formatting.

In all I am fine now. Thanks for your help any ways.


Author Closing Comment

ID: 31411024
Gave me some clues which helped in resolution.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

867 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

21 Experts available now in Live!

Get 1:1 Help Now