Windows 窗体 DataGridView 控件和 DataGrid 控件之间的区别Differences Between the Windows Forms DataGridView and DataGrid Controls

DataGridView控件是新控件,用于替换DataGrid控件。The DataGridView control is a new control that replaces the DataGrid control. DataGridView控件提供了许多的基本和高级功能,中缺少DataGrid控件。The DataGridView control provides numerous basic and advanced features that are missing in the DataGrid control. 此外的体系结构DataGridView控件,可以更轻松地扩展和自定义比DataGrid控件。Additionally, the architecture of the DataGridView control makes it much easier to extend and customize than the DataGrid control.

下表描述中提供的主要功能的一些DataGridView控件中缺少DataGrid控件。The following table describes a few of the primary features available in the DataGridView control that are missing from the DataGrid control.

DataGridView 控件功能DataGridView control feature 描述Description
多个列类型Multiple column types DataGridView控件提供了更多的内置列类型,而不DataGrid控件。The DataGridView control provides more built-in column types than the DataGrid control. 这些列类型满足最常见的方案,但也更轻松地扩展或替换中的列类型比DataGrid控件。These column types meet the needs of most common scenarios, but are also easier to extend or replace than the column types in the DataGrid control. 有关详细信息,请参阅Windows 窗体 DataGridView 控件中的列类型For more information, see Column Types in the Windows Forms DataGridView Control.
通过多种方式来显示数据Multiple ways to display data DataGrid控件仅限于从外部数据源显示数据。The DataGrid control is limited to displaying data from an external data source. DataGridView控件,但是,可以显示未绑定的数据一起存储在控件、 数据绑定的数据源或绑定和未绑定的数据。The DataGridView control, however, can display unbound data stored in the control, data from a bound data source, or bound and unbound data together. 您还可以实现中的虚拟模式DataGridView控件提供自定义数据管理。You can also implement virtual mode in the DataGridView control to provide custom data management. 有关详细信息,请参阅Windows 窗体 DataGridView 控件中的数据显示模式For more information, see Data Display Modes in the Windows Forms DataGridView Control.
通过多种方式自定义数据显示Multiple ways to customize the display of data DataGridView控件提供了很多属性和事件,使您可以指定如何格式化和显示数据。The DataGridView control provides many properties and events that enable you to specify how data is formatted and displayed. 例如,您可以更改的单元格、 行和列,具体取决于它们所包含的数据外观或一种数据类型的数据替换为等效的另一种类型的数据。For example, you can change the appearance of cells, rows, and columns depending on the data they contain, or you can replace data of one data type with equivalent data of another type. 有关详细信息,请参阅Windows 窗体 DataGridView 控件中的数据格式设置For more information, see Data Formatting in the Windows Forms DataGridView Control.
更改单元格、 行、 列和标头的外观和行为的多个选项Multiple options for changing cell, row, column, and header appearance and behavior DataGridView控件使您可以使用以下几个方面的各网格组件。The DataGridView control enables you to work with individual grid components in numerous ways. 例如,可以冻结行和列,以防止其滚动,则为隐藏行、 列和标头;更改调整行、 列和标头大小; 方法更改用户进行选择; 的方式并为每个单元格、 行和列提供工具提示和快捷方式菜单。For example, you can freeze rows and columns to prevent them from scrolling; hide rows, columns, and headers; change the way row, column, and header sizes are adjusted; change the way users make selections; and provide ToolTips and shortcut menus for individual cells, rows, and columns.

DataGrid向后兼容性和特殊需要保留控件。The DataGrid control is retained for backward compatibility and for special needs. 对于几乎所有,应使用DataGridView控件。For nearly all purposes, you should use the DataGridView control. 现已推出的唯一功能DataGrid中不可用的控件DataGridView控件是在单个控件中的两个相关表中的信息的层次结构显示。The only feature that is available in the DataGrid control that is not available in the DataGridView control is the hierarchical display of information from two related tables in a single control. 必须使用两个DataGridView控件显示的主/从关系中的两个表中的信息。You must use two DataGridView controls to display information from two tables that are in a master/detail relationship.

升级到 DataGridView 控件Upgrading to the DataGridView Control

如果你的现有应用程序使用DataGrid控件在简单数据绑定方案中而无需自定义项,只需可以使用新的控件替换的旧控件。If you have existing applications that use the DataGrid control in a simple data-bound scenario without customizations, you can simply replace the old control with the new control. 这两个控件使用标准 Windows 窗体数据绑定体系结构,因此DataGridView控件将显示为无需其他配置的绑定的数据。Both controls use the standard Windows Forms data-binding architecture, so the DataGridView control will display your bound data with no additional configuration needed. 可能需要考虑利用数据绑定的改进,但是,通过将绑定到数据BindingSource组件,然后可以绑定到DataGridView控件。You might want to consider taking advantage of data-binding improvements, however, by binding your data to a BindingSource component, which you can then bind to the DataGridView control. 有关详细信息,请参阅BindingSource 组件For more information, see BindingSource Component.

因为DataGridView控件具有一个全新体系结构,没有简单的转换路径,您可以使用DataGrid自定义项与DataGridView控件。Because the DataGridView control has an entirely new architecture, there is no straightforward conversion path that will enable you to use DataGrid customizations with the DataGridView control. 许多DataGrid自定义项都是使用不必要DataGridView控制,但是,由于新控件中提供的内置功能。Many DataGrid customizations are unnecessary with the DataGridView control, however, because of the built-in features available in the new control. 如果已创建的自定义列类型DataGrid你想要用于控件DataGridView控件,将具有用于实现它们再次使用新的体系结构。If you have created custom column types for the DataGrid control that you want to use with the DataGridView control, you will have to implement them again using the new architecture. 有关详细信息,请参阅自定义 Windows 窗体 DataGridView 控件For more information, see Customizing the Windows Forms DataGridView Control.

请参阅See also