The DataGridView control and its related classes are designed to be a flexible, extensible system for displaying and editing tabular data. These classes are all contained in the System.Windows.Forms namespace, and they are all named with the "DataGridView" prefix.
The values of this enumeration can be combined with the bitwise logical operators, so the State property can express more than one state at once. For example, a DataGridViewElement can be simultaneously Frozen, Selected, and Visible.
The cell is the fundamental unit of interaction for the DataGridView. Display is centered on cells, and data entry is often performed through cells. You can access cells by using the Cells collection of the DataGridViewRow class, and you can access the selected cells by using the SelectedCells collection of the DataGridView control. The following object model illustrates this usage and shows the DataGridViewCell inheritance hierarchy.
The DataGridViewCell type is an abstract base class, from which all cell types derive. DataGridViewCell and its derived types are not Windows Forms controls, but some host Windows Forms controls. Any editing functionality supported by a cell is typically handled by a hosted control.
DataGridViewCell objects do not control their own appearance and painting features in the same way as Windows Forms controls. Instead, the DataGridView is responsible for the appearance of its DataGridViewCell objects. You can significantly affect the appearance and behavior of cells by interacting with the DataGridView control's properties and events. When you have special requirements for customizations that are beyond the capabilities of the DataGridView control, you can implement your own class that derives from DataGridViewCell or one of its child classes.
The following list shows the classes derived from DataGridViewCell:
The schema of the DataGridView control's attached data store is expressed in the DataGridView control's columns. You can access the DataGridView control's columns by using the Columns collection. You can access the selected columns by using the SelectedColumns collection. The following object model illustrates this usage and shows the DataGridViewColumn inheritance hierarchy.
Some of the key cell types have corresponding column types. These are derived from the DataGridViewColumn base class.
Cells that support advanced editing functionality typically use a hosted control that is derived from a Windows Forms control. These controls also implement the IDataGridViewEditingControl interface. The following object model illustrates the usage of these controls.
The following editing controls are provided with the DataGridView control:
The DataGridViewRow class displays a record's data fields from the data store to which the DataGridView control is attached. You can access the DataGridView control's rows by using the Rows collection. You can access the selected rows by using the SelectedRows collection. The following object model illustrates this usage and shows the DataGridViewRow inheritance hierarchy.
You can derive your own types from the DataGridViewRow class, although this will typically not be necessary. The DataGridView control has several row-related events and properties for customizing the behavior of its DataGridViewRow objects.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET Desktop feedback
feedback
.NET Desktop feedback
is an open source project. Select a link to provide feedback:
Learn how to use the `DataGridView` control to show read-only views of a small amount of data, or scale it to show editable views of very large sets of data.