DataGridView.AutoSizeRowsMode DataGridView.AutoSizeRowsMode DataGridView.AutoSizeRowsMode DataGridView.AutoSizeRowsMode Property


获取或设置一个值,该值指示如何确定行高。Gets or sets a value indicating how row heights are determined.

 property System::Windows::Forms::DataGridViewAutoSizeRowsMode AutoSizeRowsMode { System::Windows::Forms::DataGridViewAutoSizeRowsMode get(); void set(System::Windows::Forms::DataGridViewAutoSizeRowsMode value); };
public System.Windows.Forms.DataGridViewAutoSizeRowsMode AutoSizeRowsMode { get; set; }
member this.AutoSizeRowsMode : System.Windows.Forms.DataGridViewAutoSizeRowsMode with get, set
Public Property AutoSizeRowsMode As DataGridViewAutoSizeRowsMode



当设置此属性时,指定的值不是有效的 DataGridViewAutoSizeRowsMode 值。The specified value when setting this property is not a valid DataGridViewAutoSizeRowsMode value.

当设置此属性时,指定的值是 AllHeadersDisplayedHeaders,且行标题被隐藏。The specified value when setting this property is AllHeaders or DisplayedHeaders and row headers are hidden.


下面的代码示例演示如何将行设置为基于行标题和所有列的内容自动调整大小。The following code example demonstrates how to set the row to automatically resize based on the contents of the row headers and all of the columns. 此代码示例摘自了如何:Windows 窗体 DataGridView 控件中的内容更改时自动调整单元格的大小。This code example is part of a larger example provided in How to: Automatically Resize Cells When Content Changes in the Windows Forms DataGridView Control.

void AutoSizeRowsMode( Object^ /*sender*/, EventArgs^ /*es*/ )
   dataGridView1->AutoSizeRowsMode = DataGridViewAutoSizeRowsMode::AllCells;
private void AutoSizeRowsMode(Object sender, EventArgs es)
    dataGridView1.AutoSizeRowsMode =
Private Sub AutoSizeRowsMode(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button7.Click

    DataGridView1.AutoSizeRowsMode = _

End Sub


此属性可让你配置控件,以便在内容发生更改时自动调整行高以适应其内容。This property lets you configure the control so that row heights are automatically adjusted to fit their contents whenever the contents change. 如果WrapMode启用,则当列宽发生变化时,还会调整行高度。If WrapMode is enabled, row heights are also adjusted whenever column widths change. 某些大小调整模式允许将大小调整限制为当前显示的行,以便提高性能。Some sizing modes let you limit the size adjustment to the currently displayed rows in order to increase performance.

只有Visible属性值为的true行才会自动调整大小,更改行的可见性不会导致调整大小。Only rows with a Visible property value of true are resized automatically, and changing the visibility of a row does not cause resizing to occur. 此外,如果将行设置为自动调整大小,则用户无法用鼠标调整行高。Additionally, when rows are set to automatically resize, the user cannot adjust the row heights with the mouse.

自动Height调整大小的行的值将在布局期间重新计算,以确定所使用字体的大小。The Height value of an automatically sized row is recalculated during layout to account for the size of the font that is used. 若要获取正确Height的,应在Layout窗体的事件而不是在窗体的构造函数中检索值。To get the correct Height, you should retrieve the value in the form's Layout event instead of in the form's constructor.

若要以编程方式调整行高, AutoResizeRowAutoResizeRows使用或方法,或设置Height行属性。To adjust row heights programmatically, use the AutoResizeRow or AutoResizeRows methods, or set the row Height 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 content-based automatic sizing, see Sizing Options in the Windows Forms DataGridView Control.