DataGridViewAutoSizeRowMode DataGridViewAutoSizeRowMode DataGridViewAutoSizeRowMode DataGridViewAutoSizeRowMode Enum


定义一些值,用于指定如何调整行的高度。Defines values for specifying how the height of a row is adjusted.

public enum class DataGridViewAutoSizeRowMode
public enum DataGridViewAutoSizeRowMode
type DataGridViewAutoSizeRowMode = 
Public Enum DataGridViewAutoSizeRowMode


AllCells AllCells AllCells AllCells 3

行高调整到适合行中所有单元格(包括标头单元格)的内容。The row height adjusts to fit the contents of all cells in the row, including the header cell.

AllCellsExceptHeader AllCellsExceptHeader AllCellsExceptHeader AllCellsExceptHeader 2

行高调整到适合行中所有单元格(不包括标头单元格)的内容。The row height adjusts to fit the contents of all cells in the row, excluding the header cell.

RowHeader RowHeader RowHeader RowHeader 1

行高调整到适合行标头的内容。The row height adjusts to fit the contents of the row header.


下面的代码示例调整大小以适应其非标头单元格的内容控件中的第三个行。The following code example resizes the third row in the control to fit the contents of its nonheader cells. 此代码示例摘自如何: 以编程方式调整大小以适应内容 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)
        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


DataGridView控件可以重新调整行基于每个行的首选高度。The DataGridView control can resize its rows based on the preferred height of each row. 首选的行高度是该行中显示的最大的单元格值所需的最小高度。The preferred row height is the minimum height required to display the largest cell value in that row. 不同的大小模式,您可以指示使用哪个单元格计算新高度 (标头单元格或非标头单元格),以及是否调整所有行或当前显示的行的大小。Different size modes let you indicate which cells are used to calculate the new heights (either header cells or non-header cells) and whether to resize all rows or only the rows that are currently displayed. 调整大小的行的子集可用于处理很多行数据时避免对性能产生负面影响。Resizing a subset of rows is useful to avoid a performance penalty when working with many rows of data.

基于内容的自动调整大小可阻止用户调整行高使用鼠标。Content-based automatic resizing prevents users from adjusting row heights with the mouse.

此枚举由DataGridView控制AutoResizeRow方法。This enumeration is used by the DataGridView control AutoResizeRow method.

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