次の方法で共有


DataGridViewCell.Style プロパティ

定義

セルのスタイルを取得または設定します。

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 コントロールは、DataGridViewCellStyle型の他のプロパティからスタイルを継承する、セル InheritedStyle プロパティによって示されるスタイルを使用してセルを表示します。 Style プロパティで指定されたスタイルは、他のすべてのセル スタイル プロパティで指定されたスタイルをオーバーライドしますが、セルの外観に影響するすべてのスタイルを必ずしも示すわけではありません。

詳細については、「 Windows フォーム DataGridView コントロールのセル スタイル」を参照してください。

適用対象

こちらもご覧ください