Windows Dev Center

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.

DataGridView Class

Displays data in a customizable grid.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
public ref class DataGridView : public Control, ISupportInitialize
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class DataGridView extends Control implements ISupportInitialize
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class DataGridView extends Control implements ISupportInitialize
Not applicable.

The DataGridView control provides a customizable table for displaying data. The DataGridView class allows customization of cells, rows, columns, and borders through the use of properties such as DefaultCellStyle, ColumnHeadersDefaultCellStyle, CellBorderStyle, and GridColor. For more information, see Basic Formatting and Styling in the Windows Forms DataGridView Control.

You can use a DataGridView control to display data with or without an underlying data source. Without specifying a data source, you can create columns and rows that contain data and add them directly to the DataGridView using the Rows and Columns properties. You can also use the Rows collection to access DataGridViewRow objects and the DataGridViewRow.Cells property to read or write cell values directly. The Item indexer also provides direct access to cells.

As an alternative to populating the control manually, you can set the DataSource and DataMember properties to bind the DataGridView to a data source and automatically populate it with data. For more information, see Displaying Data in the Windows Forms DataGridView Control.

When working with very large amounts of data, you can set the VirtualMode property to true to display a subset of the available data. Virtual mode requires the implementation of a data cache from which the DataGridView control is populated. For more information, see Data Display Modes in the Windows Forms DataGridView Control.

For additional information about the features available in the DataGridView control, see DataGridView Control (Windows Forms). The following table provides direct links to common tasks.

TopicLocation
How to: Change the Type of a Windows Forms DataGridView Column Using the Designer
How to: Bind Data to the Windows Forms DataGridView Control Using the Designer
How to: Set Default Cell Styles and Data Formats for the Windows Forms DataGridView Control Using the Designer
How to: Change the Type of a Windows Forms DataGridView Column Using the DesignerWindows Forms Controls
How to: Bind Data to the Windows Forms DataGridView Control Using the DesignerWindows Forms Controls
How to: Set Default Cell Styles and Data Formats for the Windows Forms DataGridView Control Using the DesignerWindows Forms Controls
How to: Bind Data to the Windows Forms DataGridView Control
How to: Add ToolTips to Individual Cells in a Windows Forms DataGridView Control
How to: Set Font and Color Styles in the Windows Forms DataGridView Control
How to: Format Data in the Windows Forms DataGridView Control
Walkthrough: Validating Data in the Windows Forms DataGridView Control
How to: Customize Data Formatting in the Windows Forms DataGridView Control
Walkthrough: Creating a Master/Detail Form Using Two Windows Forms DataGridView Controls
How to: Bind Data to the Windows Forms DataGridView ControlWindows Forms Controls in the .NET Framework SDK
How to: Add ToolTips to Individual Cells in a Windows Forms DataGridView ControlWindows Forms Controls in the .NET Framework SDK
How to: Set Font and Color Styles in the Windows Forms DataGridView ControlWindows Forms Controls in the .NET Framework SDK
How to: Format Data in the Windows Forms DataGridView ControlWindows Forms Controls in the .NET Framework SDK
Walkthrough: Validating Data in the Windows Forms DataGridView ControlWindows Forms Controls in the .NET Framework SDK
How to: Customize Data Formatting in the Windows Forms DataGridView ControlWindows Forms Controls in the .NET Framework SDK
Walkthrough: Creating a Master/Detail Form Using Two Windows Forms DataGridView ControlsWindows Forms Controls in the .NET Framework SDK
How to: Bind Data to the Windows Forms DataGridView Control
How to: Add ToolTips to Individual Cells in a Windows Forms DataGridView Control
How to: Set Font and Color Styles in the Windows Forms DataGridView Control
How to: Change the Type of a Windows Forms DataGridView Column Using the Designer
How to: Bind Data to the Windows Forms DataGridView Control Using the Designer
How to: Set Default Cell Styles and Data Formats for the Windows Forms DataGridView Control Using the Designer
How to: Format Data in the Windows Forms DataGridView Control
Walkthrough: Validating Data in the Windows Forms DataGridView Control
How to: Customize Data Formatting in the Windows Forms DataGridView Control
Walkthrough: Creating a Master/Detail Form Using Two Windows Forms DataGridView Controls

Although the DataGridView control replaces and adds functionality to the DataGrid control of previous versions, the DataGrid control is retained for both backward compatibility and future use if you choose. For more information, see Differences Between the Windows Forms DataGridView and DataGrid Controls.

NoteNote:

The DataGridView control inherits both the ContextMenu and ContextMenuStrip properties from Control, but supports only the ContextMenuStrip property. Using the ContextMenu property with the DataGridView control has no effect.

The following code example demonstrates how to initialize an unbound DataGridView control.

No code example is currently available or this language may not be supported.

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
        System.Windows.Forms.DataGridView

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

Show:
© 2015 Microsoft