DataGridView.AutoResizeRow Method

Definition

调整指定行的高度以适应其单元格的内容。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 不在 0 到行数减 1 的有效范围内。rowIndex is not in the valid range of 0 to the number of rows minus 1.

Examples

下面的代码示例将调整 DataGridView 中第三行的大小以适合列内容。The following code example resizes the third row in a DataGridView to fit the column contents. 此代码示例摘自如何:以编程方式调整单元格大小以适应 Windows 窗体 DataGridView 控件中的内容的更大示例。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. 若要调整所有行的大小,请使用 AutoResizeRows 方法。To resize all rows, use the AutoResizeRows method. 若要将行设置为在其内容更改时自动调整大小,请使用 AutoSizeRowsMode 属性。To set the row to automatically resize whenever its contents change, use the AutoSizeRowsMode property.

当调整行大小时,若要将单元格内容换行,则单元格的有效单元格样式的 WrapMode 属性值必须为 TrueFor 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.

有关以编程方式调整大小的详细信息,请参阅Windows 窗体 DataGridView 控件中的调整大小选项For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.

See also

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.

Exceptions

autoSizeRowMode 具有值 RowHeader,且 RowHeadersVisiblefalseautoSizeRowMode has the value RowHeader and RowHeadersVisible is false.

autoSizeRowMode 不是有效的 DataGridViewAutoSizeRowMode 值。autoSizeRowMode is not a valid DataGridViewAutoSizeRowMode value.

rowIndex 不在 0 到行数减 1 的有效范围内。rowIndex is not in the valid range of 0 to the number of rows minus 1.

Examples

下面的代码示例将调整 DataGridView 中第三行的大小以适合列内容。The following code example resizes the third row in a DataGridView to fit the column contents. 此代码示例摘自如何:以编程方式调整单元格大小以适应 Windows 窗体 DataGridView 控件中的内容的更大示例。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. 若要调整所有行的大小,请使用 AutoResizeRows 方法。To resize all rows, use the AutoResizeRows method. 若要将行设置为在其内容更改时自动调整大小,请使用 AutoSizeRowsMode 属性。To set the row to automatically resize whenever its contents change, use the AutoSizeRowsMode property.

当调整行大小时,若要将单元格内容换行,则单元格的有效单元格样式的 WrapMode 属性值必须为 TrueFor 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.

有关以编程方式调整大小的详细信息,请参阅Windows 窗体 DataGridView 控件中的调整大小选项For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.

See also

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.

fixedWidth
Boolean

如果要基于列的当前宽度计算新高度,则为 true;如果要在列宽也进行调整的假定条件下计算高度,则为 falsetrue 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 具有值 RowHeader,且 RowHeadersVisiblefalseautoSizeRowMode has the value RowHeader and RowHeadersVisible is false.

autoSizeRowMode 不是有效的 DataGridViewAutoSizeRowMode 值。autoSizeRowMode is not a valid DataGridViewAutoSizeRowMode value.

rowIndex 不在 0 到行数减 1 的有效范围内。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. 若要调整所有行的大小,请使用 AutoResizeRows 方法。To resize all rows, use the AutoResizeRows method. 若要将行设置为在其内容更改时自动调整大小,请使用 AutoSizeRowsMode 属性。To set the row to automatically resize whenever its contents change, use the AutoSizeRowsMode property.

当调整行大小时,若要将单元格内容换行,则单元格的有效单元格样式的 WrapMode 属性值必须为 TrueFor 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.

此重载受到保护,旨在使您能够在派生的 DataGridView 类中实现理想的单元格高度与宽度的比率。This overload is protected and is designed to enable you to achieve ideal cell height-to-width ratios in a derived DataGridView class. 如果 false``fixedWidth,则将根据您将调用 AutoResizeColumnAutoResizeColumns 方法的预期来计算行高。If fixedWidth is false, the row height will be calculated with the expectation that you will call the AutoResizeColumn or AutoResizeColumns method next.

有关以编程方式调整大小的详细信息,请参阅Windows 窗体 DataGridView 控件中的调整大小选项For more information about programmatic resizing, see Sizing Options in the Windows Forms DataGridView Control.

See also

Applies to