Share via


How to: Display Data in a Windows Forms DataGridView Control

You can display data in a DataGridView control by dragging items from the Data Sources Window onto your form. Prior to dragging from the Data Sources window, set the control type of the table to DataGridView (this is the default setting for top-level items in the Data Sources window). For more information, see How to: Set the Control to be Created when Dragging from the Data Sources Window. An alternative to displaying data in a grid is to display the data in individual controls. For more information, see How to: Display Data in Individual Windows Forms Controls.

Data can be displayed in a new DataGridView or in an existing one. When you drag items onto an existing grid, any previously established data bindings are replaced with the new items.

Displaying Data in a DataGridView Control

To display data in a new Windows Forms DataGridView control

  1. Open the Data Sources window. For more information, see How to: Open the Data Sources Window.

    Note

    If the Data Sources window is empty, then add a data source to it. For more information, see Data Sources Overview.

  2. Open the form in the Windows Forms Designer.

  3. Select a table in the Data Sources window, click the drop-down arrow, and then select DataGridView.

  4. Drag the table from the Data Sources window to a form.

    A DataGridView control and a tool strip (BindingNavigator) for navigating records appear on the form. A DataSet, TableAdapter, BindingSource, and BindingNavigator appear in the component tray.

To display data in an existing Windows Forms DataGridView control

  1. Open the Data Sources window. For more information, see How to: Open the Data Sources Window.

    Note

    If the Data Sources window is empty, then add a data source to it. For more information, see Data Sources Overview.

  2. Open your form in the Windows Forms Designer.

  3. Select a table in the Data Sources window, click the drop-down arrow, and then select DataGridView.

  4. Drag the table from the Data Sources window onto a DataGridView on the form.

    The DataGridView control is now bound to the table that you have dragged onto it. A DataSet, TableAdapter, and BindingSource appear in the component tray.

See Also

Tasks

How to: Display Data in Individual Windows Forms Controls

How to: Add Custom Controls to the Data Sources Window

How to: Validate Data During Column Changes

Concepts

Displaying Data Overview

Data Sources Overview

Reference

DataGridView Control Overview (Windows Forms)

Other Resources

BindingSource Component

BindingNavigator Control (Windows Forms)