DataGridView.AutoResizeRowHeadersWidth Method

Definition

Adjusts the width of the row headers to fit the header contents.

Overloads

AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode)

Adjusts the width of the row headers using the specified size mode.

AutoResizeRowHeadersWidth(Int32, DataGridViewRowHeadersWidthSizeMode)

Adjusts the width of the row headers based on changes to the contents of the header in the specified row and using the specified size mode.

AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode, Boolean, Boolean)

Adjusts the width of the row headers using the specified size mode, optionally calculating the width with the expectation that the row and/or column header widths will subsequently be adjusted.

AutoResizeRowHeadersWidth(Int32, DataGridViewRowHeadersWidthSizeMode, Boolean, Boolean)

Adjusts the width of the row headers based on changes to the contents of the header in the specified row and using the specified size mode, optionally calculating the width with the expectation that the row and/or column header widths will subsequently be adjusted.

AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode)

Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs

Adjusts the width of the row headers using the specified size mode.

C#
public void AutoResizeRowHeadersWidth(System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode);

Parameters

Exceptions

rowHeadersWidthSizeMode has the value EnableResizing or DisableResizing.

rowHeadersWidthSizeMode is not a valid DataGridViewRowHeadersWidthSizeMode value.

Remarks

This method is useful if you want to control when the row headers resize. The width of the row headers is adjusted only once per method call; if the contents of the row headers later change, the row headers will not automatically adjust. To set the row headers to automatically resize when their contents change, use the RowHeadersWidthSizeMode property.

This method lets you specify a sizing mode that calculates the new width based on values in a limited set of headers, such as those in displayed rows only. This improves performance when the control contains a large number of rows.

For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

AutoResizeRowHeadersWidth(Int32, DataGridViewRowHeadersWidthSizeMode)

Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs

Adjusts the width of the row headers based on changes to the contents of the header in the specified row and using the specified size mode.

C#
public void AutoResizeRowHeadersWidth(int rowIndex, System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode);

Parameters

rowIndex
Int32

The index of the row header with the changed content.

Exceptions

rowIndex is not in the valid range of 0 to the number of rows minus 1.

rowHeadersWidthSizeMode has the value EnableResizing or DisableResizing

rowHeadersWidthSizeMode is not a valid DataGridViewRowHeadersWidthSizeMode value.

Examples

The following code example illustrates how to resize the row header widths based on changes to the contents of the first row header. This code example is part of a larger example provided in How to: Programmatically Resize Cells to Fit Content in the Windows Forms DataGridView Control.

C#
private void SizeFirstRowHeaderToAllHeaders(Object sender, EventArgs e)
{
    dataGridView1.AutoResizeRowHeadersWidth(
        0, DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
}

Remarks

This method is useful if you want to control when the row headers resize if only the contents of the header in the specified row have changed as a result of user edits or changes to a bound data source. The width of the row headers is adjusted only once per method call if the content change requires it; if the contents of the row headers later change, the row headers will not automatically adjust. To set the row headers to automatically resize when their contents change, use the RowHeadersWidthSizeMode property.

This method lets you specify a sizing mode that calculates the new width based on values in a limited set of headers, such as those in displayed rows only. This improves performance when the control contains a large number of rows.

For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode, Boolean, Boolean)

Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs

Adjusts the width of the row headers using the specified size mode, optionally calculating the width with the expectation that the row and/or column header widths will subsequently be adjusted.

C#
protected void AutoResizeRowHeadersWidth(System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, bool fixedColumnHeadersHeight, bool fixedRowsHeight);

Parameters

fixedColumnHeadersHeight
Boolean

true to calculate the new width based on the current height of the column headers; false to calculate the width with the expectation that the height of the column headers will also be adjusted.

fixedRowsHeight
Boolean

true to calculate the new width based on the current row heights; false to calculate the width with the expectation that the row heights will also be adjusted.

Exceptions

rowHeadersWidthSizeMode has the value EnableResizing or DisableResizing.

rowHeadersWidthSizeMode is not a valid DataGridViewRowHeadersWidthSizeMode value.

Remarks

This method is useful if you want to control when the row headers resize. The width of the row headers is adjusted only once per method call; if the contents of the row headers later change, the row headers will not automatically adjust. To set the row headers to automatically resize when their contents change, use the RowHeadersWidthSizeMode property.

This method lets you specify a sizing mode that calculates the new width based on values in a limited set of headers, such as those in displayed rows only. This improves performance when the control contains a large number of rows.

This overload is protected and is designed to enable you to achieve ideal cell height-to-width ratios in a derived DataGridView class. If the fixedColumnHeadersHeight or fixedRowsHeight parameters are false, the width of the row headers will be calculated with the expectation that you will call methods such as AutoResizeRows and AutoResizeColumnHeadersHeight next.

For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

AutoResizeRowHeadersWidth(Int32, DataGridViewRowHeadersWidthSizeMode, Boolean, Boolean)

Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs

Adjusts the width of the row headers based on changes to the contents of the header in the specified row and using the specified size mode, optionally calculating the width with the expectation that the row and/or column header widths will subsequently be adjusted.

C#
protected void AutoResizeRowHeadersWidth(int rowIndex, System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, bool fixedColumnHeadersHeight, bool fixedRowHeight);

Parameters

rowIndex
Int32

The index of the row containing the header with the changed content.

fixedColumnHeadersHeight
Boolean

true to calculate the new width based on the current height of the column headers; false to calculate the width with the expectation that the height of the column headers will also be adjusted.

fixedRowHeight
Boolean

true to calculate the new width based on the current height of the specified row; false to calculate the width with the expectation that the row height will also be adjusted.

Exceptions

rowIndex is not in the valid range of 0 to the number of rows minus 1.

rowHeadersWidthSizeMode has the value EnableResizing or DisableResizing.

rowHeadersWidthSizeMode is not a valid DataGridViewRowHeadersWidthSizeMode value.

Remarks

This method is useful if you want to control when the row headers resize if only the contents of the header in the specified row have changed as a result of user edits or changes to a bound data source. The width of the row headers is adjusted only once per method call if the content change requires it; if the contents of the row headers later change, the row headers will not automatically adjust. To set the row headers to automatically resize when their contents change, use the RowHeadersWidthSizeMode property.

This method lets you specify a sizing mode that calculates the new width based on values in a limited set of headers, such as those in displayed rows only. This improves performance when the control contains a large number of rows.

This overload is protected, and is designed to enable you to achieve ideal cell height-to-width ratios in a derived DataGridView class. If the fixedColumnHeadersHeight or fixedRowHeight parameters are false, the width of the row headers will be calculated with the expectation that you will call methods such as AutoResizeRows and AutoResizeColumnHeadersHeight next.

For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10