Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 20th, 2013, 04:44 PM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2013
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old February 20th, 2013, 05:09 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,153, Level: 23
Points: 3,153, Level: 23 Points: 3,153, Level: 23 Points: 3,153, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 643
Thanks: 2
Thanked 96 Times in 95 Posts
Default

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.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #3 (permalink)  
Old February 20th, 2013, 07:27 PM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2013
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Default

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.
  #4 (permalink)  
Old February 21st, 2013, 09:49 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,153, Level: 23
Points: 3,153, Level: 23 Points: 3,153, Level: 23 Points: 3,153, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 643
Thanks: 2
Thanked 96 Times in 95 Posts
Default

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.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
The Following User Says Thank You to Rod Stephens For This Useful Post:
Mech_1000 (February 27th, 2013)
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 21 Confused econophil BOOK: JavaScript 24-Hour Trainer 1 January 7th, 2013 10:42 AM
Errors LESSON CS 28 & 29 FINAL MRGLENN BOOK: PHP and MySQL 24-Hour Trainer 2 December 7th, 2012 08:06 PM
Lesson 21 Try It Cristina BOOK: Java Programming 24-Hour Trainer by Yakov Fain 0 March 28th, 2012 02:58 AM
handling all types of errors kliu9 Excel VBA 2 March 9th, 2005 12:06 PM



All times are GMT -4. The time now is 01:58 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.