DataGridViewCell.Style Właściwość

Definicja

Pobiera lub ustawia styl komórki.

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

Wartość właściwości

DataGridViewCellStyle

Styl skojarzony z komórką.

Atrybuty

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą Style właściwości uzyskać kolor tła komórki. Ten przykład jest częścią większego przykładu kodu udostępnionego DataGridViewColumn dla klasy.

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

Uwagi

Kontrolka DataGridView wyświetla komórki przy użyciu stylów wskazywanych przez właściwość komórki InheritedStyle , która dziedziczy style z innych właściwości typu DataGridViewCellStyle. Style określone za pomocą Style właściwości zastępują style określone we wszystkich innych właściwościach stylu komórki, ale niekoniecznie wskazują wszystkie style, które przyczyniają się do wyglądu komórki.

Aby uzyskać więcej informacji, zobacz Style komórek w kontrolce DataGridView Windows Forms.

Dotyczy

Zobacz też