Export (0) Print
Expand All
Expand Minimize

DataGridViewAutoSizeColumnMode Enumeration

Defines values for specifying how the width of a column is adjusted.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public enum DataGridViewAutoSizeColumnMode

Member nameDescription
NotSetThe sizing behavior of the column is inherited from the DataGridView.AutoSizeColumnsMode property.
NoneThe column width does not automatically adjust.
AllCellsThe column width adjusts to fit the contents of all cells in the column, including the header cell.
AllCellsExceptHeaderThe column width adjusts to fit the contents of all cells in the column, excluding the header cell.
DisplayedCellsThe column width adjusts to fit the contents of all cells in the column that are in rows currently displayed onscreen, including the header cell.
DisplayedCellsExceptHeaderThe column width adjusts to fit the contents of all cells in the column that are in rows currently displayed onscreen, excluding the header cell.
ColumnHeaderThe column width adjusts to fit the contents of the column header cell.
FillThe 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 DataGridViewColumn.MinimumWidth property values. Relative column widths are determined by the relative DataGridViewColumn.FillWeight property values.

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.

This enumeration is used by the AutoSizeMode and InheritedAutoSizeMode properties of columns and the DataGridView.AutoResizeColumn method.

For more information about sizing modes, see Sizing Options in the Windows Forms DataGridView Control. For more information about column fill mode in particular, see Column Fill Mode in the Windows Forms DataGridView Control.

The following code example illustrates the use of this enumeration to configure a fixed-width column. 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;


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft