DataGridViewCell.Style 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定細胞的風格。
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; }
[<System.ComponentModel.Browsable(true)>]
member this.Style : System.Windows.Forms.DataGridViewCellStyle with get, set
Public Property Style As DataGridViewCellStyle
屬性值
與細胞相關的風格。
- 屬性
範例
以下程式碼範例示範如何利用該 Style 屬性取得儲存格的背景色。 這個範例是本類別提供 DataGridViewColumn 更大型程式碼範例的一部分。
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
備註
控制項 DataGridView 使用格子屬性所 InheritedStyle 指示的樣式來顯示其儲存格,該屬性繼承自其他屬性 DataGridViewCellStyle的樣式。 屬性 Style 所指定的樣式會覆蓋所有其他單元風格屬性所指定的樣式,但不一定代表所有對單元外觀有貢獻的樣式。
欲了解更多資訊,請參閱 Windows 表單 DataGridView 控制項中的儲存格樣式。