|
 |
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
 | This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|

February 20th, 2013, 05:44 PM
|
Registered User
|
|
Join Date: Feb 2013
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Lesson 21 Try It (Handling Errors)
Hello,
For the most part I understand what the code is saying/doing, however I ran into an odd issue with this lessons example and hoping somebody could explain whats wrong and possibly how to fix it.
When I input new item values correctly and calculate, the OK button enables.
I change a value to something that would have an error and press OK.
An error handler processes and a window appears "Price < 0". I press OK.
The new items form closes when it shouldn't and the list adds the item, with the previous correct calculated values.
Notes:
I changed the OK button to NOT be the accept button
this.DialogResult = DialogResult.OK only occurs if ValuesAreOk() returns true
I can even comment out //this.DialogResult = DialogResult.OK, the same results occur.
---This tells me somewhere in the code/compiler it still believes the Ok button is the default Accept Button...
The only way to fix this error I have found was to erase the Ok button code, delete the button, create a new Okay button, paste the code into its click_event handler... Why do I have to completely delete the button to fix this issue? Is there something silly I am missing or not doing? There isn't much code and objects, I've double checked everything and compared it to the downloaded working example (which works)...
Thanks for the help
|

February 20th, 2013, 06:09 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
|
|
If the code looks like the downloaded version and it's behaving differently, then there's probably a property that's set differently on the form at design time.
In this case, my guess is that the OK button's DialogResult property is set to OK. (When you make a button the AcceptButton, it sets the DialogResult value and it doesn't change it back if you later make some other button the AcceptButton.)
So I'd check the OK button's DialogResult property and make sure it's set to None. If that doesn't work, let me know.
|

February 20th, 2013, 08:27 PM
|
Registered User
|
|
Join Date: Feb 2013
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Thanks I found the problem.
I changed the AcceptButton to None on the form itself, however it was still thinking the OK button was the AcceptButton. I looked into the auto generated code and the button still had this code:
this.okayButton.DialogResult = System.Windows.Forms.DialogResult.OK;
Commented it out and the program worked properly...
Is there any reason why this auto generated code didnt correct itself when I changed the forms properties? I even saved and rebuilt the form. But at any rate, its good to know where to look for future reference if a similar error persists.
|

February 21st, 2013, 10:49 AM
|
 |
Wrox Author
|
|
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
|
|
These are two different properties.
The form's AcceptButton property determines what button gets fired when the user presses Enter.
A button's DialogResult property determines what value the form returns as a dialog if the button is pressed.
The only relation is that normally when you set the AcceptButton property the IDE may automatically also set the button's DialogResult property. If you unset AcceptButton, it doesn't unset DialogResult.
Instead of commenting out that line of code, you could have reset the button's DialogResult property in the Properties window.
|
The Following User Says Thank You to Rod Stephens For This Useful Post:
|
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |
All times are GMT -4. The time now is 03:58 AM.
|