Ok, new day, new problem.
I worked through the Lesson 17 Try It, and set the Preferred Contact to 0, like this:
Code:
preferredMethodComboBox.SelectedIndex = 0;
When I ran it, I kept getting an error message that it was out of range.
I replaced the "0" with -1, 1 and 2, and kept getting the error.
Finally, I guessed it was something with the Properties of the preferredMethodComboBox. Comparing mine to the one in your book's downloadable example, I found that my combobox did not have any entries in its "Items".
I thought that was what the code was supposed to do ... initialize the combobox with those Items, and assign indexes to them.
After typing in "None, Email, Phone and Snailmail" into Edit Items for the combobox, the error messages went away and the solution worked.
So what is the purpose of this code? :
Code:
private enum ContactMethod
{
None = -1,
Email = 0,
Phone = 1,
SnailMail = 2,
}
I thought it was supposed to set the indexes for those selections, but None is still 0, Email is 1, Phone is 2, SnailMail is 3.
That is,
preferredMethodComboBox.SelectedIndex = 0;
brings up "None" when I thought it would be "Email"
Your sample code works the same way, 0 is None, not Email.