DataGridView.RowTemplate 屬性

定義

取得或設定表示控制項中所有資料列之樣板的資料列。

public:
 property System::Windows::Forms::DataGridViewRow ^ RowTemplate { System::Windows::Forms::DataGridViewRow ^ get(); void set(System::Windows::Forms::DataGridViewRow ^ value); };
[System.ComponentModel.Browsable(true)]
public System.Windows.Forms.DataGridViewRow RowTemplate { get; set; }
[<System.ComponentModel.Browsable(true)>]
member this.RowTemplate : System.Windows.Forms.DataGridViewRow with get, set
Public Property RowTemplate As DataGridViewRow

屬性值

DataGridViewRow

表示資料列範本的 DataGridViewRow

屬性

例外狀況

設定這個屬性時所指定的資料列已設定其 DataGridView 屬性。

範例

下列程式碼範例說明如何使用資料列範本來指定初始資料列高度和最小資料列高度。

DataGridViewRow^ row = this->dataGridView1->RowTemplate;
row->DefaultCellStyle->BackColor = Color::Bisque;
row->Height = 35;
row->MinimumHeight = 20;
DataGridViewRow row = this.dataGridView1.RowTemplate;
row.DefaultCellStyle.BackColor = Color.Bisque;
row.Height = 35;
row.MinimumHeight = 20;
With Me.dataGridView1.RowTemplate
    .DefaultCellStyle.BackColor = Color.Bisque
    .Height = 35
    .MinimumHeight = 20
End With

備註

有時候您想要更充分控制資料列的外觀 DataGridView ,而不是各種 DataGridView 儲存格樣式屬性所提供的資料列外觀。 屬性 RowTemplate 可讓您建立和初始化 DataGridViewRow ,以供所有資料列作為範本使用,如果 為 AllowUserToAddRows true ,則包括新記錄的資料列。

當您設定資料列高度等屬性的預設值時,這非常有用。 例如,您可能想要增加預設資料列高度,以便在一般儲存格內容下方提供額外的空間,以顯示跨越多個資料行的內容。

使用衍生自 類別的 DataGridViewRow 自訂類型顯示外部資料時,需要設定資料列範本。 使用未系結 DataGridView 的控制項,您可以使用自訂資料列類型的實例,以程式設計方式填入 Rows 集合。 不過,顯示外部資料時,會自動產生資料列,但資料列是以資料列範本為基礎,您可以將其設定為自訂資料列類型的實例。

如果未在第一次擷取此屬性的值時設定此屬性,則會建立並傳回新的 DataGridViewRow

適用於

另請參閱