System.Windows.Forms.DataGridViewColumn.AutoSizeMode Property

Gets or sets the mode by which the column automatically adjusts its width.

Syntax

[System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)]
[System.ComponentModel.DefaultValue(System.Windows.Forms.DataGridViewAutoSizeColumnMode.NotSet)]
public DataGridViewAutoSizeColumnMode AutoSizeMode { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

The automatic sizing behavior of the column is determined by the value of the DataGridViewColumn.InheritedAutoSizeMode property, which is the same as the value of the DataGridViewColumn.AutoSizeMode property for all values except DataGridViewAutoSizeColumnMode.NotSet, which indicates that the value is inherited from the DataGridView.AutoSizeColumnsMode property instead.

When the DataGridViewColumn.InheritedAutoSizeMode property value is DataGridViewAutoSizeColumnMode.Fill, the column is resized along with other columns in that mode. All fill-mode columns in the control divide the available space in proportions determined by their DataGridViewColumn.FillWeight property values. The width available for fill mode is determined by subtracting the widths of all other columns from the width of the client area of the control. If this width is smaller than the combined DataGridViewColumn.MinimumWidth values of all fill-mode columns, the horizontal scroll bar is displayed, all fill-mode columns are shown with their minimum widths, and user column-resizing is disabled. For more information about column fill mode, see Column Fill Mode in the Windows Forms DataGridView Control.

When the DataGridViewColumn.InheritedAutoSizeMode property is set to any other value except DataGridViewAutoSizeColumnMode.None, the column will manage its width so that its cell values are fully displayed without clipping. In content-based sizing modes, size adjustments occur whenever cell contents change or, if DataGridViewCellStyle.WrapMode is enabled, whenever row heights change. Some content-based sizing modes let you limit the size adjustment to the currently displayed rows in order to increase performance.

Only columns with a DataGridViewColumn.Visible property value of true are resized, and changing the visibility of a column does not cause resizing to occur. Additionally, when columns are set to automatically resize, the user cannot adjust the column widths with the mouse.

To adjust column widths programmatically, use the System.Windows.Forms.DataGridView control's erload:System.Windows.Forms.DataGridView.AutoResizeColumn or erload:System.Windows.Forms.DataGridView.AutoResizeColumns methods or set the column DataGridViewColumn.Width property.

For more information about content-based automatic sizing, see Sizing Options in the Windows Forms DataGridView Control.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0