DataGridViewAutoSizeColumnMode 枚举


定义用于指定如何调整列宽的值。Defines values for specifying how the width of a column is adjusted.

public enum class DataGridViewAutoSizeColumnMode
public enum DataGridViewAutoSizeColumnMode
type DataGridViewAutoSizeColumnMode = 
Public Enum DataGridViewAutoSizeColumnMode


AllCells 6

调整列宽,以适合该列中的所有单元格的内容,包括标题单元格。The column width adjusts to fit the contents of all cells in the column, including the header cell.

AllCellsExceptHeader 4

调整列宽,以适合该列中的所有单元格的内容,不包括标题单元格。The column width adjusts to fit the contents of all cells in the column, excluding the header cell.

ColumnHeader 2

调整列宽,以适合列标题单元格的内容。The column width adjusts to fit the contents of the column header cell.

DisplayedCells 10

调整列宽,以适合当前屏幕上显示的行的列中的所有单元格的内容,包括标题单元格。The column width adjusts to fit the contents of all cells in the column that are in rows currently displayed onscreen, including the header cell.

DisplayedCellsExceptHeader 8

调整列宽,以适合当前屏幕上显示的行的列中的所有单元格的内容,不包括标题单元格。The column width adjusts to fit the contents of all cells in the column that are in rows currently displayed onscreen, excluding the header cell.

Fill 16

调整列宽,使所有列的宽度正好填充控件的显示区域,只需要水平滚动保证列宽在 MinimumWidth 属性值以上。The column width adjusts so that the widths of all columns exactly fills the display area of the control, requiring horizontal scrolling only to keep column widths above the MinimumWidth property values. 相对列宽由相对 FillWeight 属性值决定。Relative column widths are determined by the relative FillWeight property values.

None 1

列宽不会自动调整。The column width does not automatically adjust.

NotSet 0

列的大小调整行为从 AutoSizeColumnsMode 属性继承。The sizing behavior of the column is inherited from the AutoSizeColumnsMode property.


下面的代码示例演示如何使用此枚举来配置固定宽度的列。The following code example illustrates the use of this enumeration to configure a fixed-width column. 此示例摘自如何:设置 Windows 窗体 DataGridView 控件的大小调整模式中提供的更大示例的一部分。This example is part of a larger example available in How to: Set the Sizing Modes of the Windows Forms DataGridView Control.

DataGridViewTextBoxColumn idColumn =
    new DataGridViewTextBoxColumn();
idColumn.HeaderText = "ID";
idColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
idColumn.Resizable = DataGridViewTriState.False;
idColumn.ReadOnly = true;
idColumn.Width = 20;
Dim idColumn As New DataGridViewTextBoxColumn()
idColumn.HeaderText = "ID"
idColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
idColumn.Resizable = DataGridViewTriState.False
idColumn.ReadOnly = True
idColumn.Width = 20


DataGridView 控件可以调整其列的大小,以使其填充控件的可用水平宽度,或使其显示所有单元格或指定单元格的全部内容。The DataGridView control can resize its columns to make them fill the available horizontal width of the control or to make them display the full contents of all cells or of specified cells.

对于填充模式,列的首选宽度是通过调整该模式中的所有列来确定的,使控件中的所有可见列都完全填充可用显示区域的水平宽度。With Fill mode, the preferred width of a column is determined by resizing all columns in that mode so that all visible columns in the control exactly fill the horizontal width of the available display area. 使用其他模式时,首选列宽是显示所有单元中的最大单元值或该列的单元子集(如当前显示的行中的单元子集)所需的最小宽度。With other modes, the preferred column width is the minimum width required to display the largest cell value from all cells or a subset of cells in that column, such as the subset of cells that are in currently displayed rows. 使用单元子集来确定新的宽度有助于避免在处理多行数据时出现性能损失。Using a subset of cells to determine the new width is useful to avoid a performance penalty when working with many rows of data.

基于内容的自动调整大小可防止用户用鼠标调整列宽。Content-based automatic resizing prevents users from adjusting column widths with the mouse. 但在填充模式下启用了用户大小调整。User resizing is enabled in fill mode, however.

此枚举由列和 DataGridView.AutoResizeColumn 方法的 AutoSizeModeInheritedAutoSizeMode 属性使用。This enumeration is used by the AutoSizeMode and InheritedAutoSizeMode properties of columns and the DataGridView.AutoResizeColumn method.

有关调整大小模式的详细信息,请参阅Windows 窗体 DataGridView 控件中的调整大小选项For more information about sizing modes, see Sizing Options in the Windows Forms DataGridView Control. 有关列填充模式的详细信息,请参阅Windows 窗体 DataGridView 控件中的列填充模式For more information about column fill mode in particular, see Column Fill Mode in the Windows Forms DataGridView Control.