DataGridView.AutoResizeRow Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adjusts the height of the specified row to fit the contents of its cells.
Overloads
AutoResizeRow(Int32) |
Adjusts the height of the specified row to fit the contents of all its cells including the header cell. |
AutoResizeRow(Int32, DataGridViewAutoSizeRowMode) |
Adjusts the height of the specified row using the specified size mode. |
AutoResizeRow(Int32, DataGridViewAutoSizeRowMode, Boolean) |
Adjusts the height of the specified row using the specified size mode, optionally calculating the height with the expectation that column widths will subsequently be adjusted. |
AutoResizeRow(Int32)
Adjusts the height of the specified row to fit the contents of all its cells including the header cell.
public:
void AutoResizeRow(int rowIndex);
public void AutoResizeRow (int rowIndex);
member this.AutoResizeRow : int -> unit
Public Sub AutoResizeRow (rowIndex As Integer)
Parameters
- rowIndex
- Int32
The index of the row to resize.
Exceptions
rowIndex
is not in the valid range of 0 to the number of rows minus 1.
Examples
The following code example resizes the third row in a DataGridView to fit the column contents. 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.
void SizeThirdRow( Object^ /*sender*/, EventArgs^ /*e*/ )
{
dataGridView1->AutoResizeRow(2, DataGridViewAutoSizeRowMode::AllCellsExceptHeader);
}
private void SizeThirdRow(Object sender, EventArgs e)
{
dataGridView1.AutoResizeRow(
2, DataGridViewAutoSizeRowMode.AllCellsExceptHeader);
}
Private Sub SizeThirdRow(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button7.Click
Dim thirdRow As Integer = 2
DataGridView1.AutoResizeRow( _
2, DataGridViewAutoSizeRowMode.AllCellsExceptHeader)
End Sub
Remarks
This method is useful if you want to control when a row resizes. The row height is adjusted only once per method call; if the contents of the row later change, the row will not automatically adjust. To resize all rows, use the AutoResizeRows method. To set the row to automatically resize whenever its contents change, use the AutoSizeRowsMode 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 programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.
See also
Applies to
AutoResizeRow(Int32, DataGridViewAutoSizeRowMode)
Adjusts the height of the specified row using the specified size mode.
public:
void AutoResizeRow(int rowIndex, System::Windows::Forms::DataGridViewAutoSizeRowMode autoSizeRowMode);
public void AutoResizeRow (int rowIndex, System.Windows.Forms.DataGridViewAutoSizeRowMode autoSizeRowMode);
member this.AutoResizeRow : int * System.Windows.Forms.DataGridViewAutoSizeRowMode -> unit
Public Sub AutoResizeRow (rowIndex As Integer, autoSizeRowMode As DataGridViewAutoSizeRowMode)
Parameters
- rowIndex
- Int32
The index of the row to resize.
- autoSizeRowMode
- DataGridViewAutoSizeRowMode
One of the DataGridViewAutoSizeRowMode values.
Exceptions
autoSizeRowMode
has the value RowHeader and RowHeadersVisible is false
.
autoSizeRowMode
is not a valid DataGridViewAutoSizeRowMode value.
rowIndex
is not in the valid range of 0 to the number of rows minus 1.
Examples
The following code example resizes the third row in a DataGridView to fit the column contents. 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.
void SizeThirdRow( Object^ /*sender*/, EventArgs^ /*e*/ )
{
dataGridView1->AutoResizeRow(2, DataGridViewAutoSizeRowMode::AllCellsExceptHeader);
}
private void SizeThirdRow(Object sender, EventArgs e)
{
dataGridView1.AutoResizeRow(
2, DataGridViewAutoSizeRowMode.AllCellsExceptHeader);
}
Private Sub SizeThirdRow(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button7.Click
Dim thirdRow As Integer = 2
DataGridView1.AutoResizeRow( _
2, DataGridViewAutoSizeRowMode.AllCellsExceptHeader)
End Sub
Remarks
This method is useful if you want to control when a row resizes. The row height is adjusted only once per method call; if the contents of the row later change, the row will not automatically adjust. To resize all rows, use the AutoResizeRows method. To set the row to automatically resize whenever its contents change, use the AutoSizeRowsMode 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.
This overload lets you specify a sizing mode that calculates the new height based on values in a limited set of cells, 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
AutoResizeRow(Int32, DataGridViewAutoSizeRowMode, Boolean)
Adjusts the height of the specified row using the specified size mode, optionally calculating the height with the expectation that column widths will subsequently be adjusted.
protected:
void AutoResizeRow(int rowIndex, System::Windows::Forms::DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth);
protected void AutoResizeRow (int rowIndex, System.Windows.Forms.DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth);
member this.AutoResizeRow : int * System.Windows.Forms.DataGridViewAutoSizeRowMode * bool -> unit
Protected Sub AutoResizeRow (rowIndex As Integer, autoSizeRowMode As DataGridViewAutoSizeRowMode, fixedWidth As Boolean)
Parameters
- rowIndex
- Int32
The index of the row to resize.
- autoSizeRowMode
- DataGridViewAutoSizeRowMode
One of the DataGridViewAutoSizeRowMode values.
- fixedWidth
- Boolean
true
to calculate the new height based on the current width of the columns; false
to calculate the height with the expectation that the column widths will also be adjusted.
Exceptions
autoSizeRowMode
has the value RowHeader and RowHeadersVisible is false
.
autoSizeRowMode
is not a valid DataGridViewAutoSizeRowMode value.
rowIndex
is not in the valid range of 0 to the number of rows minus 1.
Remarks
This method is useful if you want to control when a row resizes. The row height is adjusted only once per method call; if the contents of the row later change, the row will not automatically adjust. To resize all rows, use the AutoResizeRows method. To set the row to automatically resize whenever its contents change, use the AutoSizeRowsMode 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.
This overload lets you specify a sizing mode that calculates the new height based on values in a limited set of cells, 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 fixedWidth
is false
, the row height will be calculated with the expectation that you will call the AutoResizeColumn or AutoResizeColumns method next.
For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.