238Microsoft Visual Studio 2010: A Beginner’s Guide

Figure 8-14 Changing the control type for a field

In Figure 8-14, the CustomerID is being changed to a ComboBox because it makes more sense to give the user the option of selecting a customer from a list for a new order, rather than typing in an ID number. Also, the object defaults to a Grid control, but in this first example, we only want to add a new order, meaning that the control type should be changed to Detail. To create a new order form with controls bound to order data, select the Order object in the Data Sources window and drag and drop the order onto the Designer of the NewOrder window. Figure 8-15 shows this new window.

Figure 8-15 shows how VS added a Grid layout with two columns and a row for each field in the Order table. As explained, the CustomerID is a ComboBox and the OrderDate is a calendar. VS was smart enough to put spaces between the words in the labels, too.

VS didn’t put the Save button on the screen, which is something you would need to do to save the data. In addition to adding controls to the Designer, VS added the following CollectionViewSource control to the NewOrder window’s XAML:

<Window.Resources>

<CollectionViewSource x:Key="orderViewSource" d:DesignSource="{d:DesignInstance my:Order, CreateList=True}" />

</Window.Resources>

Page 261
Image 261
Microsoft 9GD00001 manual Changing the control type for a field