Export (0) Print
Expand All
Expand Minimize
1 out of 1 rated this helpful - Rate this topic

DataGridView.AutoSizeRowsMode Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets a value indicating how row heights are determined.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public DataGridViewAutoSizeRowsMode AutoSizeRowsMode { get; set; }
/** @property */
public DataGridViewAutoSizeRowsMode get_AutoSizeRowsMode ()

/** @property */
public void set_AutoSizeRowsMode (DataGridViewAutoSizeRowsMode value)

public function get AutoSizeRowsMode () : DataGridViewAutoSizeRowsMode

public function set AutoSizeRowsMode (value : DataGridViewAutoSizeRowsMode)

Property Value

A DataGridViewAutoSizeRowsMode value indicating the sizing mode. The default is None.
Exception typeCondition

InvalidEnumArgumentException

The specified value when setting this property is not a valid DataGridViewAutoSizeRowsMode value.

InvalidOperationException

The specified value when setting this property is AllHeaders or DisplayedHeaders and row headers are hidden.

This property lets you configure the control so that row heights are automatically adjusted to fit their contents whenever the contents change. If WrapMode is enabled, row heights are also adjusted whenever column widths change. Some sizing modes let you limit the size adjustment to the currently displayed rows in order to increase performance.

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

To adjust row heights programmatically, use the AutoResizeRow or AutoResizeRows methods, or set the row Height property.

For cell contents to wrap onto multiple lines when a row is resized, the cell style in effect for the cell must have a WrapMode property value of True.

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

The following code example demonstrates how to set the row to automatically resize based on the contents of the row headers and all of the columns. This code example is part of a larger example provided in How to: Automatically Resize Cells When Content Changes in the Windows Forms DataGridView Control.

private void AutoSizeRowsMode(Object sender, EventArgs es)
{
    dataGridView1.AutoSizeRowsMode =
        DataGridViewAutoSizeRowsMode.AllCells;
}

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.