다음을 통해 공유


DataGridView Control Technology Summary (Windows Forms)

This topic summarizes information about the DataGridView control and the classes that support its use.

Displaying data in a tabular format is a task you are likely to perform frequently. The DataGridView control is designed to be a complete solution for presenting data in a grid.

Keywords

DataGridView, BindingSource, table, cell, data binding, virtual mode

Namespaces

System.Windows.Forms

System.Data

BindingSource

Background

User interface (UI) designers frequently find it necessary to display tabular data to users. The .NET Framework provides several ways to show data in a table or grid. The DataGridView control represents the latest evolution of this technology for Windows Forms applications.

The DataGridView control can display rows of data from a data store. Many types of data stores are supported. The data store can hold simple, untyped data, such as a one-dimensional array, or it can hold typed data, such as a DataSet. For more information, see How to: Bind Data to the Windows Forms DataGridView Control.

The DataGridView control provides a powerful and flexible way to display data in a tabular format. You can use the control to show read-only or editable views of small to very large sets of data.

You can extend the DataGridView control in several ways to build custom behavior into your applications. For example, you can programmatically specify your own sorting algorithms, and you can create your own types of cells. You can easily customize the appearance of the DataGridView control by choosing among several properties. Many types of data stores can be used as a data source, or the DataGridView control can operate without a data source bound to it.

Implementing DataGridView Classes

There are several ways for you to take advantage of the DataGridView control's extensibility features. You can customize many aspects of the control through events and properties, but some customizations require you to create new classes derived from existing DataGridView classes.

The most typically used base classes are DataGridViewCell and DataGridViewColumn. You can derive your own cell class from DataGridViewCell or any of its child classes. Although you can add any cell type to any column, you will typically also derive a companion column class from DataGridViewColumn that hosts cells of your custom cell type by default.

You can implement the IDataGridViewEditingCell interface in your derived cell class to create a cell type that has editing functionality but does not host a control in editing mode. To create a control that you can host in a cell in editing mode, you can implement the IDataGridViewEditingControl interface in a class derived from Control.

For more information, see How to: Customize Cells and Columns in the Windows Forms DataGridView Control by Extending Their Behavior and Appearance and How to: Host Controls in Windows Forms DataGridView Cells.

DataGridView Classes at a Glance

System.Windows.Forms

Technology Area Classes/interfaces/configuration elements

Data Binding

BindingSource

Data Presentation

DataGridView

DataGridViewCell and derived classes

DataGridViewRow and derived classes

DataGridViewColumn and derived classes

DataGridViewCellStyle

DataGridView Extensibility

DataGridViewCell and derived classes

DataGridViewColumn and derived classes

IDataGridViewEditingCell

IDataGridViewEditingControl

What's New

The DataGridView control is designed to be a complete solution for displaying tabular data with Windows Forms. You should consider using the DataGridView control before other solutions, such as DataGrid, when you are authoring a new application. For more information, see Differences Between the Windows Forms DataGridView and DataGrid Controls.

The DataGridView control can work in close conjunction with the BindingSource component. This component is designed to be the primary data source of a form. It can manage the interaction between a DataGridView control and its data source, regardless of the data source type.

See Also

Reference

DataGridView Control Overview (Windows Forms)

Concepts

DataGridView Control Architecture (Windows Forms)
Securing Connection Strings