DataGridView.AutoResizeRow 方法

定义

调整指定行的高度以适应其单元格的内容。Adjusts the height of the specified row to fit the contents of its cells.

重载

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)

参数

rowIndex
Int32

要调整大小的行的索引。The index of the row to resize.

异常

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

示例

下面的代码示例将 DataGridView 中的第三行调整大小以适合列内容。The following code example resizes the third row in a DataGridView to fit the column contents. 此代码示例摘自 [How 中提供的一个更大的示例:以编程方式调整单元格大小以适应 Windows 窗体 DataGridView 控件 @ no__t 中的内容。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

注解

如果要控制行的调整时间,此方法非常有用。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. 若要将行设置为在其内容更改时自动调整大小,请使用 @no__t 的属性。To set the row to automatically resize whenever its contents change, use the AutoSizeRowsMode property.

若要在调整行大小时将单元格内容换行到多行,对单元格有效的单元格样式必须将 WrapMode 属性值设置 @no__t。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.

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

另请参阅

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)

参数

rowIndex
Int32

要调整大小的行的索引。The index of the row to resize.

异常

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.

示例

下面的代码示例将 DataGridView 中的第三行调整大小以适合列内容。The following code example resizes the third row in a DataGridView to fit the column contents. 此代码示例摘自 [How 中提供的一个更大的示例:以编程方式调整单元格大小以适应 Windows 窗体 DataGridView 控件 @ no__t 中的内容。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

注解

如果要控制行的调整时间,此方法非常有用。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. 若要将行设置为在其内容更改时自动调整大小,请使用 @no__t 的属性。To set the row to automatically resize whenever its contents change, use the AutoSizeRowsMode property.

若要在调整行大小时将单元格内容换行到多行,对单元格有效的单元格样式必须将 WrapMode 属性值设置 @no__t。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.

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

另请参阅

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)

参数

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.

异常

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.

注解

如果要控制行的调整时间,此方法非常有用。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. 若要将行设置为在其内容更改时自动调整大小,请使用 @no__t 的属性。To set the row to automatically resize whenever its contents change, use the AutoSizeRowsMode property.

若要在调整行大小时将单元格内容换行到多行,对单元格有效的单元格样式必须将 WrapMode 属性值设置 @no__t。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.

此重载受到保护,旨在使你能够在派生 @no__t 0 类中实现理想的单元格高度与宽度的比率。This overload is protected and is designed to enable you to achieve ideal cell height-to-width ratios in a derived DataGridView class. 如果 fixedWidth @no__t 为-1,则将计算行高,并将调用第二 @no__t 或 @no__t 方法。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.

另请参阅

适用于