Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
6 out of 19 rated this helpful - Rate this topic

Walkthrough: Displaying Data on a Form in a Windows Application 

One of the most common scenarios in application development is to display data on a form in a Windows-based application. You can display data on a form by dragging items from the Data Sources Window onto the form. This walkthrough creates a simple form that displays data from a single table in several individual controls. This example uses the Customers table from the Northwind sample database.

Tasks illustrated in this walkthrough include:

In order to complete this walkthrough, you need:

The first step is to create a Windows Application project.

To create the new Windows Application project

  1. From the File menu, create a new project.

  2. Name the project DisplayingDataonaWindowsForm.

  3. Select Windows Application and click OK. For more information, see Creating Windows-based Applications.

    The DisplayingDataonaWindowsForm project is created and added to Solution Explorer.

This step creates a data source using the Data Source Configuration Wizard based on the Customers table in the Northwind sample database. You must have access to the Northwind sample database to create the connection. For information on setting up the Northwind sample database, see How to: Install Sample Databases.

To create the data source

  1. On the Data menu, click Show Data Sources.

  2. In the Data Sources window, select Add New Data Source to start the Data Source Configuration Wizard.

  3. Select Database on the Choose a Data Source Type page, and then click Next.

  4. On the Choose your Data Connection page do one of the following:

    • If a data connection to the Northwind sample database is available in the drop-down list, select it.

      -or-

    • Select New Connection to launch the Add/Modify Connection dialog box. For more information, see Add/Modify Connection Dialog Box (General).

  5. If your database requires a password, select the option to include sensitive data, and then click Next.

  6. Click Next on the Save connection string to the Application Configuration file page.

  7. Expand the Tables node on the Choose your Database Objects page.

  8. Select the Customers table, and then click Finish.

    The NorthwindDataSet is added to your project and the Customers table appears in the Data Sources window.

For this walkthrough the data will be in a Details layout where data is displayed in individual controls. (The alternative approach is the default Grid layout where the data is displayed in a DataGridView control.)

To set the drop type for the items in the Data Sources window

  1. Expand the Customers node in the Data Sources window.

  2. Change the drop type of the Customers table to Details by selecting Details from the drop-down list on the Customers node. For more information, see How to: Set the Control to be Created when Dragging from the Data Sources Window.

  3. Change the CustomerID column's drop type to a label by selecting Label from the control list on the CustomerID node.

Create the data-bound controls by dragging items from the Data Sources window onto your form.

To create data-bound controls on the form

To run the application

  • Press F5.

  • Navigate records using the BindingNavigator control.

Depending on your application requirements, there are several steps you may want to perform after creating a data-bound Windows Form. Some enhancements you could make to this walkthrough include:

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.