DataGridView.AutoResizeRows DataGridView.AutoResizeRows DataGridView.AutoResizeRows DataGridView.AutoResizeRows Method

定义

调整某些或所有行的高度以适应其内容。Adjusts the heights of some or all rows to fit their contents.

重载

AutoResizeRows(DataGridViewAutoSizeRowsMode) AutoResizeRows(DataGridViewAutoSizeRowsMode) AutoResizeRows(DataGridViewAutoSizeRowsMode) AutoResizeRows(DataGridViewAutoSizeRowsMode)

使用指定的大小调整模式值调整行高。Adjusts the heights of the rows using the specified size mode value.

AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean) AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean) AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean) AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean)

使用指定的大小调整模式调整指定行的高度,还可以选择在列宽随后进行调整的假定条件下计算高度。Adjusts the heights of the specified rows using the specified size mode, optionally calculating the heights with the expectation that column widths will subsequently be adjusted.

AutoResizeRows() AutoResizeRows() AutoResizeRows() AutoResizeRows()

调整所有行的高度以适应其所有单元格(包括标题单元格)的内容。Adjusts the heights of all rows to fit the contents of all their cells, including the header cells.

AutoResizeRows(DataGridViewAutoSizeRowsMode, Boolean) AutoResizeRows(DataGridViewAutoSizeRowsMode, Boolean) AutoResizeRows(DataGridViewAutoSizeRowsMode, Boolean) AutoResizeRows(DataGridViewAutoSizeRowsMode, Boolean)

使用指定的大小调整模式调整所有行的高度,还可以选择在列宽随后进行调整的假定条件下计算高度。Adjusts the heights of all rows using the specified size mode, optionally calculating the heights with the expectation that column widths will subsequently be adjusted.

AutoResizeRows(DataGridViewAutoSizeRowsMode) AutoResizeRows(DataGridViewAutoSizeRowsMode) AutoResizeRows(DataGridViewAutoSizeRowsMode) AutoResizeRows(DataGridViewAutoSizeRowsMode)

使用指定的大小调整模式值调整行高。Adjusts the heights of the rows using the specified size mode value.

public:
 void AutoResizeRows(System::Windows::Forms::DataGridViewAutoSizeRowsMode autoSizeRowsMode);
public void AutoResizeRows (System.Windows.Forms.DataGridViewAutoSizeRowsMode autoSizeRowsMode);
member this.AutoResizeRows : System.Windows.Forms.DataGridViewAutoSizeRowsMode -> unit
Public Sub AutoResizeRows (autoSizeRowsMode As DataGridViewAutoSizeRowsMode)

参数

异常

autoSizeRowsMode 具有值 NoneautoSizeRowsMode has the value None.

示例

下面的代码示例演示如何基于非标题单元格内容调整所有行的大小。The following code example demonstrates how to resize all rows based on non-header cell content. 此代码示例摘自了如何:以编程方式调整单元格大小以适应 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 SizeAllRows( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   dataGridView1->AutoResizeRows(DataGridViewAutoSizeRowsMode::AllCellsExceptHeaders);
}

private void SizeAllRows(Object sender,
    EventArgs e)
{
    dataGridView1.AutoResizeRows(
        DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders);
}
Private Sub SizeAllRows(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button11.Click

    DataGridView1.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders)

End Sub

注解

如果要控制行的调整时间,此方法非常有用。This method is useful if you want to control when rows resize. 对于每个方法调用,行高只进行一次调整;如果后续行的内容发生更改,则不会自动调整行。The row heights are adjusted only once per method call; if the contents of the rows later change, the rows will not automatically adjust. 若要调整特定行的大小, AutoResizeRow请使用方法。To resize a specific row, use the AutoResizeRow method. 若要调整行子集的大小,请AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean)使用重载。To resize a subset of rows, use the AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean) overload. 若要将行设置为在其内容更改时自动调整大小AutoSizeRowsMode ,请使用属性。To set the rows to automatically resize whenever their contents change, use the AutoSizeRowsMode property.

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

另请参阅

AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean) AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean) AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean) AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean)

使用指定的大小调整模式调整指定行的高度,还可以选择在列宽随后进行调整的假定条件下计算高度。Adjusts the heights of the specified rows using the specified size mode, optionally calculating the heights with the expectation that column widths will subsequently be adjusted.

protected:
 void AutoResizeRows(int rowIndexStart, int rowsCount, System::Windows::Forms::DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth);
protected void AutoResizeRows (int rowIndexStart, int rowsCount, System.Windows.Forms.DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth);
member this.AutoResizeRows : int * int * System.Windows.Forms.DataGridViewAutoSizeRowMode * bool -> unit
Protected Sub AutoResizeRows (rowIndexStart As Integer, rowsCount As Integer, autoSizeRowMode As DataGridViewAutoSizeRowMode, fixedWidth As Boolean)

参数

rowIndexStart
Int32 Int32 Int32 Int32

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

rowsCount
Int32 Int32 Int32 Int32

要调整大小的行数。The number of rows to resize.

fixedWidth
Boolean Boolean Boolean Boolean

如果基于当前的列宽计算新高度,则为 true;如果在列宽也进行调整的假定条件下计算高度,则为 falsetrue to calculate the new heights based on the current column widths; false to calculate the heights with the expectation that the column widths will also be adjusted.

异常

autoSizeRowsMode 具有值 NoneautoSizeRowsMode has the value None.

rowIndexStart 小于 0。rowIndexStart is less than 0.

- 或 --or- rowsCount 小于 0。rowsCount is less than 0.

注解

如果要控制行的大小调整,则此方法非常有用,但您希望只调整行的特定子集的大小,例如那些已更新的绑定记录范围内的行。This method is useful if you want to control when rows resize, but you want to resize only a specific subset of rows, such as those within a range of bound records that have been updated. 仅对每个方法调用调整指定行的行高;如果后续行的内容发生更改,则不会自动调整行。The row heights for the specified rows are adjusted only once per method call; if the contents of the rows later change, the rows will not automatically adjust. 若要调整特定行的大小, AutoResizeRow请使用方法。To resize a specific row, use the AutoResizeRow method. 若要调整所有行的大小,请使用AutoResizeRows方法的其他重载。To resize all rows, use a different overload of the AutoResizeRows method. 若要将行设置为在其内容更改时自动调整大小AutoSizeRowsMode ,请使用属性。To set the rows to automatically resize whenever their contents change, use the AutoSizeRowsMode property.

当调整行大小时,若要将单元格内容换行,则单元格的有效单元格样式的WrapMode属性True值必须为。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 heights 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,则将按您将调用AutoResizeColumnAutoResizeColumns方法的预期计算行高度。 fixedWidthIf the fixedWidth parameter is false, the row heights 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.

另请参阅

AutoResizeRows() AutoResizeRows() AutoResizeRows() AutoResizeRows()

调整所有行的高度以适应其所有单元格(包括标题单元格)的内容。Adjusts the heights of all rows to fit the contents of all their cells, including the header cells.

public:
 void AutoResizeRows();
public void AutoResizeRows ();
member this.AutoResizeRows : unit -> unit
Public Sub AutoResizeRows ()

示例

下面的代码示例演示如何基于非标题单元格内容调整所有行的大小。The following code example demonstrates how to resize all rows based on non-header cell content. 此代码示例摘自了如何:以编程方式调整单元格大小以适应 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 SizeAllRows( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   dataGridView1->AutoResizeRows(DataGridViewAutoSizeRowsMode::AllCellsExceptHeaders);
}

private void SizeAllRows(Object sender,
    EventArgs e)
{
    dataGridView1.AutoResizeRows(
        DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders);
}
Private Sub SizeAllRows(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button11.Click

    DataGridView1.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders)

End Sub

注解

如果要控制行的调整时间,此方法非常有用。This method is useful if you want to control when rows resize. 对于每个方法调用,行高只进行一次调整;如果后续行的内容发生更改,则不会自动调整行。The row heights are adjusted only once per method call; if the contents of the rows later change, the rows will not automatically adjust. 若要调整特定行的大小, AutoResizeRow请使用方法。To resize a specific row, use the AutoResizeRow method. 若要调整行子集的大小,请AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean)使用重载。To resize a subset of rows, use the AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean) overload. 若要将行设置为在其内容更改时自动调整大小AutoSizeRowsMode ,请使用属性。To set the rows to automatically resize whenever their contents change, use the AutoSizeRowsMode property.

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

另请参阅

AutoResizeRows(DataGridViewAutoSizeRowsMode, Boolean) AutoResizeRows(DataGridViewAutoSizeRowsMode, Boolean) AutoResizeRows(DataGridViewAutoSizeRowsMode, Boolean) AutoResizeRows(DataGridViewAutoSizeRowsMode, Boolean)

使用指定的大小调整模式调整所有行的高度,还可以选择在列宽随后进行调整的假定条件下计算高度。Adjusts the heights of all rows using the specified size mode, optionally calculating the heights with the expectation that column widths will subsequently be adjusted.

protected:
 void AutoResizeRows(System::Windows::Forms::DataGridViewAutoSizeRowsMode autoSizeRowsMode, bool fixedWidth);
protected void AutoResizeRows (System.Windows.Forms.DataGridViewAutoSizeRowsMode autoSizeRowsMode, bool fixedWidth);
member this.AutoResizeRows : System.Windows.Forms.DataGridViewAutoSizeRowsMode * bool -> unit
Protected Sub AutoResizeRows (autoSizeRowsMode As DataGridViewAutoSizeRowsMode, fixedWidth As Boolean)

参数

fixedWidth
Boolean Boolean Boolean Boolean

如果基于当前的列宽计算新高度,则为 true;如果在列宽也进行调整的假定条件下计算高度,则为 falsetrue to calculate the new heights based on the current column widths; false to calculate the heights with the expectation that the column widths will also be adjusted.

异常

autoSizeRowsMode 具有值 NoneautoSizeRowsMode has the value None.

注解

如果要控制行的调整时间,此方法非常有用。This method is useful if you want to control when rows resize. 对于每个方法调用,行高只进行一次调整;如果后续行的内容发生更改,则不会自动调整行。The row heights are adjusted only once per method call; if the contents of the rows later change, the rows will not automatically adjust. 若要调整特定行的大小, AutoResizeRow请使用方法。To resize a specific row, use the AutoResizeRow method. 若要调整行子集的大小,请AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean)使用重载。To resize a subset of rows, use the AutoResizeRows(Int32, Int32, DataGridViewAutoSizeRowMode, Boolean) overload. 若要将行设置为在其内容更改时自动调整大小AutoSizeRowsMode ,请使用属性。To set the rows to automatically resize whenever their contents change, use the AutoSizeRowsMode property.

当调整行大小时,若要将单元格内容换行,则单元格的有效单元格样式的WrapMode属性True值必须为。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 heights 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,则将按您将调用AutoResizeColumnAutoResizeColumns方法的预期计算行高度。 fixedWidthIf the fixedWidth parameter is false, the row heights 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.

另请参阅

适用于