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 Search this Thread Display Modes
  #1 (permalink)  
Old July 22nd, 2013, 09:20 PM
Authorized User
Points: 179, Level: 3
Points: 179, Level: 3 Points: 179, Level: 3 Points: 179, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Lesson 17, Try It (again)

Ok, no it does not work.

I opened the solution provided in your source code download, and it works, but only because the items in the enumeration were manually entered into the Designer. (preferredMethodComboBox, Items Property, Collection).

If you go into the Designer and remove (or change) the Items that are listed in the Collection, the Build displays the modified Items, not the enumeration used in the code.

The enumeration is ignored, apparently.

not sure why.

Completely removing all Items from the Collection in the Designer causes the code to crash at:

preferredMethodComboBox.SelectedIndex = 0;

(again, the Build ignores the code and looks to the Collection in the Items Property)

You'll also notice that the code ignores the attempt to set the Indexes in the enumeration.

The way I finally got my attempt at the project to work was to go into the Designer and duplicate the items in the enumeration into the Items for the ComboBox.

The code does not work without doing that, so it's like double work!
  #2 (permalink)  
Old July 22nd, 2013, 10:57 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Yes, the example didn't do that.

Don't do it if you don't want to. The idea is so the code can use the enumeration but as you point out it isn't complete.
__________________
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 July 23rd, 2013, 05:21 PM
Authorized User
Points: 179, Level: 3
Points: 179, Level: 3 Points: 179, Level: 3 Points: 179, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, but still unsure of what an enumeration actually does.

Are they used that often?

I have two other books on C#, and they hardly mention enums at all.

Is it something you see often?
  #4 (permalink)  
Old July 23rd, 2013, 05:41 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

You see them fairly often and you see them a lot in the .NET Framework. They do two things.

First they define a type. For example, if you need to let someone specify one of the values North, South, East, West, then you can define an enumeration named CompassDirection. Now I can declare a variable or parameter of that type and you have to use one of the allowed values. For example, if my TurnShip method takes a CompassDirection parameter, you cannot pass it the value 13.

Second, the define the values. In this example, the enumeration defines the values North, South, East, West.

To see why this is useful, suppose you don't have an enumeration. The TurnShip method could take a parameter that is a number (1 = North, 2 = South, etc.). But then you could pass the method the value 5 and confuse it.

Or TurnShip could take a string parameter ("North," "South," etc.). But then you could pass the method the value "down" and again confuse it.

The enumeration gives you strong type checking so Visual Studio can tell at design time whether the value you pass to TurnShip makes sense.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 17 Try It John S BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 7 June 14th, 2013 09:27 PM
Lesson 8 - Try It Femi Sonuga BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 4 February 12th, 2012 08:44 AM
Lesson 17 alawode BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 1 February 2nd, 2012 09:48 PM
Lesson 9 MTMike BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 3 November 3rd, 2011 01:51 PM
Lesson 8 sergeySE BOOK: Java Programming 24-Hour Trainer by Yakov Fain 1 June 29th, 2011 09:49 AM



All times are GMT -4. The time now is 09:43 PM.


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