Bagikan melalui


DataGridViewCell.Style Properti

Definisi

Mendapatkan atau mengatur gaya untuk sel.

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

Nilai Properti

Gaya yang terkait dengan sel.

Atribut

Contoh

Contoh kode berikut menunjukkan cara menggunakan Style properti untuk mendapatkan warna latar belakang sel. Contoh ini adalah bagian dari contoh kode yang lebih besar yang disediakan untuk DataGridViewColumn kelas .

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

Keterangan

Kontrol DataGridView menampilkan selnya menggunakan gaya yang ditunjukkan oleh properti sel InheritedStyle , yang mewarisi gaya dari properti tipe DataGridViewCellStylelainnya. Gaya yang ditentukan melalui Style properti mengambil alih gaya yang ditentukan melalui semua properti gaya sel lainnya, tetapi tidak selalu menunjukkan semua gaya yang berkontribusi pada tampilan sel.

Untuk informasi selengkapnya, lihat Gaya Sel di Kontrol Windows Forms DataGridView.

Berlaku untuk

Lihat juga