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

Значение свойства

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 свойства, переопределяют стили, заданные всеми другими свойствами стиля ячейки, но не обязательно указывают все стили, которые влияют на внешний вид ячейки.

Подробнее см. в статье Стили ячеек элемента управления DataGridView в Windows Forms.

Применяется к

См. также раздел