DataGridView.AutoResizeRowHeadersWidth 方法

定义

调整行标题的宽度以适应标题内容。Adjusts the width of the row headers to fit the header contents.

重载

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)

使用指定的大小调整模式调整行标题的宽度。Adjusts the width of the row headers using the specified size mode.

public:
 void AutoResizeRowHeadersWidth(System::Windows::Forms::DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode);
public void AutoResizeRowHeadersWidth (System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode);
member this.AutoResizeRowHeadersWidth : System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode -> unit
Public Sub AutoResizeRowHeadersWidth (rowHeadersWidthSizeMode As DataGridViewRowHeadersWidthSizeMode)

参数

异常

rowHeadersWidthSizeMode 具有值 EnableResizingDisableResizingrowHeadersWidthSizeMode has the value EnableResizing or DisableResizing.

rowHeadersWidthSizeMode 不是有效的 DataGridViewRowHeadersWidthSizeMode 值。rowHeadersWidthSizeMode is not a valid DataGridViewRowHeadersWidthSizeMode value.

注解

如果要控制行标题的大小调整,此方法非常有用。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. 若要将行标题设置为在其内容更改时自动调整大小,请使用 RowHeadersWidthSizeMode 属性。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.

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

另请参阅

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.

public:
 void AutoResizeRowHeadersWidth(int rowIndex, System::Windows::Forms::DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode);
public void AutoResizeRowHeadersWidth (int rowIndex, System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode);
member this.AutoResizeRowHeadersWidth : int * System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode -> unit
Public Sub AutoResizeRowHeadersWidth (rowIndex As Integer, rowHeadersWidthSizeMode As DataGridViewRowHeadersWidthSizeMode)

参数

rowIndex
Int32

内容已更改的行标题的索引。The index of the row header with the changed content.

异常

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

rowHeadersWidthSizeMode 具有值 EnableResizingDisableResizingrowHeadersWidthSizeMode has the value EnableResizing or DisableResizing

rowHeadersWidthSizeMode 不是有效的 DataGridViewRowHeadersWidthSizeMode 值。rowHeadersWidthSizeMode is not a valid DataGridViewRowHeadersWidthSizeMode value.

示例

下面的代码示例演示如何根据第一个行标题的内容的更改调整行标题的宽度。The following code example illustrates how to resize the row header widths based on changes to the contents of the first row header. 此代码示例摘自 [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 SizeFirstRowHeaderToAllHeaders( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   dataGridView1->AutoResizeRowHeadersWidth(0, DataGridViewRowHeadersWidthSizeMode::AutoSizeToAllHeaders);
}


private void SizeFirstRowHeaderToAllHeaders(Object sender, EventArgs e)
{
    dataGridView1.AutoResizeRowHeadersWidth(
        0, DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
}
Private Sub SizeFirstRowHeaderToAllHeaders(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button8.Click

    DataGridView1.AutoResizeRowHeadersWidth( _
        DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders)

End Sub

注解

如果您想要控制行标题调整行标题的时间,如果用户编辑或更改了绑定数据源,则此方法很有用。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. 若要将行标题设置为在其内容更改时自动调整大小,请使用 RowHeadersWidthSizeMode 属性。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.

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

另请参阅

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.

protected:
 void AutoResizeRowHeadersWidth(System::Windows::Forms::DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, bool fixedColumnHeadersHeight, bool fixedRowsHeight);
protected void AutoResizeRowHeadersWidth (System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, bool fixedColumnHeadersHeight, bool fixedRowsHeight);
member this.AutoResizeRowHeadersWidth : System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode * bool * bool -> unit
Protected Sub AutoResizeRowHeadersWidth (rowHeadersWidthSizeMode As DataGridViewRowHeadersWidthSizeMode, fixedColumnHeadersHeight As Boolean, fixedRowsHeight As Boolean)

参数

fixedColumnHeadersHeight
Boolean

如果要基于列标题的当前高度计算新宽度,则为true ;如果要在列标题的高度也进行调整的假定条件下计算宽度,则为 falsetrue 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;如果要在行高也进行调整的假定条件下计算宽度,则为 falsetrue 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.

异常

rowHeadersWidthSizeMode 具有值 EnableResizingDisableResizingrowHeadersWidthSizeMode has the value EnableResizing or DisableResizing.

rowHeadersWidthSizeMode 不是有效的 DataGridViewRowHeadersWidthSizeMode 值。rowHeadersWidthSizeMode is not a valid DataGridViewRowHeadersWidthSizeMode value.

注解

如果要控制行标题的大小调整,此方法非常有用。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. 若要将行标题设置为在其内容更改时自动调整大小,请使用 RowHeadersWidthSizeMode 属性。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.

此重载受到保护,旨在使你能够在派生 @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. 如果 @no__t 0 或 @no__t 1 参数 @no__t 为-2,则将计算行标题的宽度,前提是将调用方法(如 AutoResizeRows 和 @no__t,接下来)。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.

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

另请参阅

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.

protected:
 void AutoResizeRowHeadersWidth(int rowIndex, System::Windows::Forms::DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, bool fixedColumnHeadersHeight, bool fixedRowHeight);
protected void AutoResizeRowHeadersWidth (int rowIndex, System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, bool fixedColumnHeadersHeight, bool fixedRowHeight);
member this.AutoResizeRowHeadersWidth : int * System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode * bool * bool -> unit
Protected Sub AutoResizeRowHeadersWidth (rowIndex As Integer, rowHeadersWidthSizeMode As DataGridViewRowHeadersWidthSizeMode, fixedColumnHeadersHeight As Boolean, fixedRowHeight As Boolean)

参数

rowIndex
Int32

某一行的索引,该行包含内容已更改的标题。The index of the row containing the header with the changed content.

fixedColumnHeadersHeight
Boolean

如果要基于列标题的当前高度计算新宽度,则为 true;如果要在列标题的高度也进行调整的假定条件下计算宽度,则为 falsetrue 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;如果要在行高也进行调整的假定条件下计算宽度,则为 falsetrue 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.

异常

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

rowHeadersWidthSizeMode 具有值 EnableResizingDisableResizingrowHeadersWidthSizeMode has the value EnableResizing or DisableResizing.

rowHeadersWidthSizeMode 不是有效的 DataGridViewRowHeadersWidthSizeMode 值。rowHeadersWidthSizeMode is not a valid DataGridViewRowHeadersWidthSizeMode value.

注解

如果您想要控制行标题调整行标题的时间,如果用户编辑或更改了绑定数据源,则此方法很有用。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. 若要将行标题设置为在其内容更改时自动调整大小,请使用 RowHeadersWidthSizeMode 属性。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.

此重载是受保护的,旨在使你能够在派生的 @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. 如果 @no__t 0 或 @no__t 1 参数 @no__t 为-2,则将计算行标题的宽度,前提是将调用方法(如 AutoResizeRows 和 @no__t,接下来)。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.

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

另请参阅

适用于