调整 Windows 窗体 DataGridView 控件中的列和行的大小Resizing Columns and Rows in the Windows Forms DataGridView Control

DataGridView 控件提供了很多用于自定义其列和行的大小调整行为的选项。The DataGridView control provides numerous options for customizing the sizing behavior of its columns and rows. 通常,DataGridView 单元不会根据其内容进行调整。Typically, DataGridView cells do not resize based on their contents. 相反,它们会剪裁大于该单元的任何显示值。Instead, they clip any display value that is larger than the cell. 如果内容显示为字符串,则单元格会在工具提示中显示它。If the content can be displayed as a string, the cell displays it in a ToolTip.

默认情况下,用户可以使用鼠标拖动行、列和标题分隔符来显示详细信息。By default, users can drag row, column, and header dividers with the mouse to show more information. 用户还可以双击分隔线,根据其内容自动调整关联的行、列或标题带区的大小。Users can also double-click a divider to automatically resize the associated row, column, or header band based on its contents.

DataGridView 控件提供属性、方法和事件,使您可以自定义或禁用所有这些用户定向的行为。The DataGridView control provides properties, methods, and events that enable you to customize or disable all of these user-directed behaviors. 此外,可以以编程方式调整行、列和标头的大小以适应其内容,也可以将其配置为在其内容更改时自动调整其大小。Additionally, you can programmatically resize rows, columns, and headers to fit their contents, or you can configure them to automatically resize themselves whenever their contents change. 您还可以将列配置为按您指定的比例将控件的可用宽度自动划分。You can also configure columns to automatically divide the available width of the control in proportions that you specify.

本节内容In This Section

Windows 窗体 DataGridView 控件中的重设大小选项Sizing Options in the Windows Forms DataGridView Control
介绍用于调整行、列和标头大小的选项。Describes the options for sizing rows, columns, and headers. 还提供了有关大小调整的属性和方法的详细信息,并介绍了常见的使用方案。Also provides details on sizing-related properties and methods, and describes common usage scenarios.

Windows 窗体 DataGridView 控件中的列填充模式Column Fill Mode in the Windows Forms DataGridView Control
详细说明列填充模式,并提供可用于试验列填充模式和其他模式的演示代码。Describes column fill mode in detail, and provides demonstration code that you can use to experiment with column fill mode and other modes.

如何:设置 Windows 窗体 DataGridView 控件的重设大小模式How to: Set the Sizing Modes of the Windows Forms DataGridView Control
描述如何为常见用途配置大小调整模式。Describes how to configure the sizing modes for common purposes.

如何:以编程方式重设单元格大小以适应 Windows 窗体 DataGridView 控件中的内容How to: Programmatically Resize Cells to Fit Content in the Windows Forms DataGridView Control
提供可用于试验编程大小的演示代码。Provides demonstration code that you can use to experiment with programmatic resizing.

如何:在 Windows 窗体 DataGridView 控件中的内容发生变化时自动重设单元格大小How to: Automatically Resize Cells When Content Changes in the Windows Forms DataGridView Control
提供了可用于尝试自动调整大小模式的演示代码。Provides demonstration code that you can use to experiment with automatic sizing modes.

参考Reference

DataGridView
提供关于 DataGridView 控件的参考文档。Provides reference documentation for the DataGridView control.

另请参阅See also