14.5 Creating Forms with the Data Form Wizard

 <  Day Day Up  >  

You want to quickly create a Windows Form application that allows you to edit tables within a database.


Technique

The Data Form Wizard is a special component within Visual Studio .NET that quickly sets up a database-editing application by asking you a series of questions using a wizard. To use the wizard, create a new Windows Form application and add a new item with Project, Add New Item. Select the Data Form Wizard template. This example uses the Northwind database to show a list of customers and the orders that each customer has placed. The first question asks for a name used for the DataSet object that is created, which for this example can be something like CustomerOrdersDS . Next, select the data connection to use by using the drop-down list or creating a new connection to the Northwind database, if one hasn't been created already. The next step allows you to select the data that the controls on the form will display. Controls can display data from tables or views. Select Customers, Orders, and Order Details from the list of tables.

You need to specify how the tables you selected are related. The Customers and the Orders tables are related because they both share a CustomerID key field. Therefore, enter a name of CustomerOrders in the name field, and select Customers as the parent table and Orders as the child table. The key field for both of these tables is CustomerID . The next relationship binds the Orders table with the Order Details table. The parent table is the Orders table, and the child is the Order Details table, each sharing a key field named OrderID .

You can further customize the amount of data that is shown by selecting the columns that are displayed. To hide a column from view, uncheck the check box next to the column name. Finally, you can control how the data controls are created. The two choices are to use DataGrid controls or to create an individual control for each data column. The DataGrid column, explained further in the next section, presents data within a spreadsheet-like view. Choosing to utilize individual controls creates separate controls for each column in the master table and a DataGrid for the detail views. This arrangement closely resembles the forms generated using Microsoft Access. You can run the generated Windows Form within your application, knowing that any record additions, deletions, and updates are automatically handled for you. Also, if you want to use the generated form as the startup form, open your project properties and specify it as the startup object within the General properties tab.

Comments

If you told us a couple of years ago that we could take a database and automatically create a full custom Windows application that edited the database tables, all without writing a single line of code, we would have thought you were crazy. Visual Studio .NET, through its extensibility model, allows you to create custom wizards and item templates for coding processes you use frequently. The Data Form Wizard is one example.

Although the Data Form Wizard does a pretty good job of creating the necessary data access code, you still want to edit it to make it a little more visually appealing. If you use the DataGrid display method, you can choose one of the predefined formats by right-clicking on the DataGrid within the Windows Form designer and selecting AutoFormat. Likewise, you can rearrange and add styles to any of the individual controls if you chose the individual control method.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net