Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Accessing Data
 How to: Display Data in a Windows F...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Data Access in Client and Middle-Tier Programming
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.

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.

    NoteNote:

    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.

    NoteNote:

    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.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker