调整 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