DataGridViewCell.Style DataGridViewCell.Style DataGridViewCell.Style DataGridViewCell.Style Property

定義

取得或設定儲存格的樣式。Gets or sets the style for the cell.

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

屬性值

與儲存格關聯的樣式。The style associated with the cell.

範例

下列程式碼範例示範如何使用Style屬性來取得儲存格的背景色彩。The following code example demonstrates how to use the Style property to get the background color of a cell. 這個範例是針對DataGridViewColumn類別提供的較大程式碼範例的一部分。This example is part of a larger code example provided for the DataGridViewColumn class.

void CustomizeCellsInThirdColumn()
{
   int thirdColumn = 2;
   DataGridViewColumn^ column = dataGridView->Columns[ thirdColumn ];
   DataGridViewCell^ cell = gcnew DataGridViewTextBoxCell;
   cell->Style->BackColor = Color::Wheat;
   column->CellTemplate = cell;
}


private void CustomizeCellsInThirdColumn()
{
    int thirdColumn = 2;
    DataGridViewColumn column =
        dataGridView.Columns[thirdColumn];
    DataGridViewCell cell = new DataGridViewTextBoxCell();

    cell.Style.BackColor = Color.Wheat;
    column.CellTemplate = cell;
}
Private Sub CustomizeCellsInThirdColumn()

    Dim thirdColumn As Integer = 2
    Dim column As DataGridViewColumn = _
        dataGridView.Columns(thirdColumn)
    Dim cell As DataGridViewCell = _
        New DataGridViewTextBoxCell()

    cell.Style.BackColor = Color.Wheat
    column.CellTemplate = cell
End Sub

備註

控制項會使用資料格InheritedStyle屬性所指示的樣式來顯示其資料格,而這會繼承類型DataGridViewCellStyle之其他屬性的樣式。 DataGridViewThe DataGridView control displays its cells using the styles indicated by the cell InheritedStyle property, which inherits styles from other properties of type DataGridViewCellStyle. 透過Style屬性指定的樣式會覆寫透過所有其他儲存格樣式屬性所指定的樣式,但不一定會指出構成儲存格外觀的所有樣式。The styles specified through the Style property override the styles specified through all other cell-style properties, but do not necessarily indicate all the styles that contribute to the cell's appearance.

如需詳細資訊,請參閱Windows Forms DataGridView 控制項中的儲存格樣式For more information, see Cell Styles in the Windows Forms DataGridView Control.

適用於

另請參閱