DataGridViewAutoSizeRowMode 枚举


定义一些值,用于指定如何调整行的高度。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 3

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

AllCellsExceptHeader 2

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

RowHeader 1

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


下面的代码示例将调整控件中第三行的大小以适应其 nonheader 单元格的内容。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.