DataGridViewAutoSizeColumnMode DataGridViewAutoSizeColumnMode DataGridViewAutoSizeColumnMode DataGridViewAutoSizeColumnMode Enum


定义用于指定如何调整列宽的值。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 AllCells AllCells AllCells 6

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

AllCellsExceptHeader AllCellsExceptHeader AllCellsExceptHeader AllCellsExceptHeader 4

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

ColumnHeader ColumnHeader ColumnHeader ColumnHeader 2

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

DisplayedCells DisplayedCells DisplayedCells 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 DisplayedCellsExceptHeader DisplayedCellsExceptHeader 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 Fill Fill 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 None None None 1

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

NotSet NotSet NotSet 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.

此枚举由AutoSizeModeInheritedAutoSizeMode列的属性和DataGridView.AutoResizeColumn方法。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.