DataGridViewCell.Style Egenskap

Definition

Hämtar eller anger formatet för cellen.

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

Egenskapsvärde

Formatet som är associerat med cellen.

Attribut

Exempel

Följande kodexempel visar hur du använder Style egenskapen för att hämta bakgrundsfärgen för en cell. Det här exemplet är en del av ett större kodexempel som tillhandahålls DataGridViewColumn för klassen.

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

Kommentarer

Kontrollen DataGridView visar sina celler med de format som anges av cellegenskapen InheritedStyle , som ärver format från andra egenskaper av typen DataGridViewCellStyle. De format som anges via Style egenskapen åsidosätter de format som anges via alla andra egenskaper i cellformat, men anger inte nödvändigtvis alla format som bidrar till cellens utseende.

Mer information finns i cellstilar i Windows Forms DataGridView Control.

Gäller för

Se även