
retrieves the corresponding items. If the user enters an order ID and some items and then clicks
Update, the program updates the order’s items.
You can download the code and resources for this Try It from the book’s web
page at
www.wrox.com or www.CSharpHelper.com/24hour.html. You can find
them in the Lesson16 folder in the download.
Lesson Requirements
Create the form shown in Figure 16-4.
Add code that creates a
Dictionary field named Orders. Set its generic type parameters to
int (for order ID) and string (for items).
Add code to the Add button that creates the new entry in the dictionary.
Add code to the Find button that retrieves the appropriate entry from the dictionary.
Add code to the Update button to update the indicated entry.
This program will be fairly fragile and will crash if you don’t enter an order ID,
enter an ID that is not an integer, try to enter the same ID twice, try to find a
nonexistent ID, and so on. Don’t worry about these problems. You learn how
to handle them later, notably in Lessons 18 and 21.
Step-by-Step
Create the form shown in Figure 16-4.
1. This is relatively straightforward. The only tricks are to set the Items TextBox’s
MultiLine and AcceptsReturn properties to True.
Add code that creates a
Dictionary named orders. Set its generic type parameters to int
(for order ID) and
string (for items).
1. Use code similar to the following ...