DataGridView.AutoSizeRowsMode DataGridView.AutoSizeRowsMode DataGridView.AutoSizeRowsMode DataGridView.AutoSizeRowsMode Property

Definition

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

public:
 property System::Windows::Forms::DataGridViewAutoSizeRowsMode AutoSizeRowsMode { System::Windows::Forms::DataGridViewAutoSizeRowsMode get(); void set(System::Windows::Forms::DataGridViewAutoSizeRowsMode value); };
public System.Windows.Forms.DataGridViewAutoSizeRowsMode AutoSizeRowsMode { get; set; }
member this.AutoSizeRowsMode : System.Windows.Forms.DataGridViewAutoSizeRowsMode with get, set
Public Property AutoSizeRowsMode As DataGridViewAutoSizeRowsMode

Property Value

Exceptions

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

Examples

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.

void AutoSizeRowsMode( Object^ /*sender*/, EventArgs^ /*es*/ )
{
   dataGridView1->AutoSizeRowsMode = DataGridViewAutoSizeRowsMode::AllCells;
}
private void AutoSizeRowsMode(Object sender, EventArgs es)
{
    dataGridView1.AutoSizeRowsMode =
        DataGridViewAutoSizeRowsMode.AllCells;
}
Private Sub AutoSizeRowsMode(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button7.Click

    DataGridView1.AutoSizeRowsMode = _
        DataGridViewAutoSizeRowsMode.AllCells

End Sub

Remarks

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.

The Height value of an automatically sized row is recalculated during layout to account for the size of the font that is used. To get the correct Height, you should retrieve the value in the form's Layout event instead of in the form's constructor.

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.

Applies to

See also