System.Windows.Forms.DataGridView Class

Displays data in a customizable grid.

See Also: DataGridView Members

Syntax

[System.Windows.Forms.Docking(System.Windows.Forms.DockingBehavior.Ask)]
[System.ComponentModel.DefaultEvent("CellContentClick")]
[System.ComponentModel.ComplexBindingProperties("DataSource", "DataMember")]
[System.ComponentModel.Editor("System.Windows.Forms.Design.DataGridViewComponentEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.ComponentModel.ComponentEditor))]
[System.ComponentModel.Designer("System.Windows.Forms.Design.DataGridViewDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
public class DataGridView : Control, System.ComponentModel.ISupportInitialize

Remarks

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

You can use a System.Windows.Forms.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 System.Windows.Forms.DataGridView using the DataGridView.Rows and DataGridView.Columns properties. You can also use the DataGridView.Rows collection to access System.Windows.Forms.DataGridViewRow objects and the DataGridViewRow.Cells property to read or write cell values directly. The DataGridView.Item(int, int) indexer also provides direct access to cells.

As an alternative to populating the control manually, you can set the DataGridView.DataSource and DataGridView.DataMember properties to bind the System.Windows.Forms.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 DataGridView.VirtualMode property to true to display a subset of the available data. Virtual mode requires the implementation of a data cache from which the System.Windows.Forms.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 System.Windows.Forms.DataGridView control, see DataGridView Control (Windows Forms). The following table provides direct links to common tasks.

dgv_tasks

Although the System.Windows.Forms.DataGridView control replaces and adds functionality to the System.Windows.Forms.DataGrid control of previous versions, the System.Windows.Forms.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.

Note:

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

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0