DataGridView.AutoSizeRowsMode 屬性


取得或設定值,指出要如何判斷資料列的高度。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 值。A DataGridViewAutoSizeRowsMode value indicating the sizing mode. 預設為 NoneThe default is None.


設定這個屬性時所指定的值不是有效的 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 Forms 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 的屬性值 TrueFor 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 Forms DataGridView 控制項中的調整大小選項For more information about content-based automatic sizing, see Sizing Options in the Windows Forms DataGridView Control.