DataGridView.ColumnHeadersDefaultCellStyle 속성

정의

기본 열 머리글 스타일을 가져오거나 설정합니다.Gets or sets the default column header style.

public:
 property System::Windows::Forms::DataGridViewCellStyle ^ ColumnHeadersDefaultCellStyle { System::Windows::Forms::DataGridViewCellStyle ^ get(); void set(System::Windows::Forms::DataGridViewCellStyle ^ value); };
public System.Windows.Forms.DataGridViewCellStyle ColumnHeadersDefaultCellStyle { get; set; }
member this.ColumnHeadersDefaultCellStyle : System.Windows.Forms.DataGridViewCellStyle with get, set
Public Property ColumnHeadersDefaultCellStyle As DataGridViewCellStyle

속성 값

기본 열 머리글 스타일을 나타내는 DataGridViewCellStyle입니다.A DataGridViewCellStyle that represents the default column header style.

예제

다음 코드 예제에서는 ColumnHeadersDefaultCellStyle, AutoSizeRowsMode, ColumnHeadersBorderStyle, CellBorderStyle, GridColor, BackgroundColor, RowHeadersVisible, SelectionMode, ColumnCountMultiSelect 속성을 설정 하는 방법을 보여 줍니다.The following code example demonstrates how to set the ColumnHeadersDefaultCellStyle, AutoSizeRowsMode, ColumnHeadersBorderStyle, CellBorderStyle, GridColor, BackgroundColor, RowHeadersVisible, SelectionMode, ColumnCount, and MultiSelect properties. 또한 코드 예제에서는 DataGridViewColumn.NameDataGridViewColumn.DefaultCellStyle 속성을 설정 하는 방법을 보여 줍니다.In addition, the code example demonstrates how to set the DataGridViewColumn.Name and DataGridViewColumn.DefaultCellStyle properties. 이 예제를 실행 하려면 dataGridView1라는 DataGridView 포함 된 양식에 코드를 붙여넣고 폼의 생성자 또는 Load 이벤트 처리기에서 SetUpDataGridView 메서드를 호출 합니다.To run this example, paste the code into a form that contains a DataGridView named dataGridView1, and then call the SetUpDataGridView method from the form's constructor or Load event handler. 모든 이벤트가 해당 이벤트 처리기와 연결 되도록 합니다.Ensure all events are associated with their event handlers.

void SetUpDataGridView()
{
   this->Controls->Add( dataGridView1 );
   dataGridView1->ColumnCount = 5;
   DataGridViewCellStyle^ style = dataGridView1->ColumnHeadersDefaultCellStyle;
   style->BackColor = Color::Navy;
   style->ForeColor = Color::White;
   style->Font = gcnew System::Drawing::Font( dataGridView1->Font,FontStyle::Bold );
   dataGridView1->EditMode = DataGridViewEditMode::EditOnEnter;
   dataGridView1->Name = "dataGridView1";
   dataGridView1->Location = Point(8,8);
   dataGridView1->Size = System::Drawing::Size( 500, 300 );
   dataGridView1->AutoSizeRowsMode = DataGridViewAutoSizeRowsMode::DisplayedCellsExceptHeaders;
   dataGridView1->ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle::Raised;
   dataGridView1->CellBorderStyle = DataGridViewCellBorderStyle::Single;
   dataGridView1->GridColor = SystemColors::ActiveBorder;
   dataGridView1->RowHeadersVisible = false;
   dataGridView1->Columns[ 0 ]->Name = "Release Date";
   dataGridView1->Columns[ 1 ]->Name = "Track";
   dataGridView1->Columns[ 1 ]->DefaultCellStyle->Alignment = DataGridViewContentAlignment::MiddleCenter;
   dataGridView1->Columns[ 2 ]->Name = "Title";
   dataGridView1->Columns[ 3 ]->Name = "Artist";
   dataGridView1->Columns[ 4 ]->Name = "Album";

   // Make the font italic for row four.
   dataGridView1->Columns[ 4 ]->DefaultCellStyle->Font = gcnew System::Drawing::Font( DataGridView::DefaultFont,FontStyle::Italic );
   dataGridView1->SelectionMode = DataGridViewSelectionMode::FullRowSelect;
   dataGridView1->MultiSelect = false;
   dataGridView1->BackgroundColor = Color::Honeydew;
   dataGridView1->Dock = DockStyle::Fill;
   dataGridView1->CellFormatting += gcnew DataGridViewCellFormattingEventHandler( this, &Form1::dataGridView1_CellFormatting );
   dataGridView1->CellParsing += gcnew DataGridViewCellParsingEventHandler( this, &Form1::dataGridView1_CellParsing );
   addNewRowButton->Click += gcnew EventHandler( this, &Form1::addNewRowButton_Click );
   deleteRowButton->Click += gcnew EventHandler( this, &Form1::deleteRowButton_Click );
   ledgerStyleButton->Click += gcnew EventHandler( this, &Form1::ledgerStyleButton_Click );
   dataGridView1->CellValidating += gcnew DataGridViewCellValidatingEventHandler( this, &Form1::dataGridView1_CellValidating );
}
private void SetUpDataGridView()
{
    this.Controls.Add(dataGridView1);
    dataGridView1.ColumnCount = 5;
    DataGridViewCellStyle style = 
        dataGridView1.ColumnHeadersDefaultCellStyle;
    style.BackColor = Color.Navy;
    style.ForeColor = Color.White;
    style.Font = new Font(dataGridView1.Font, FontStyle.Bold);

    dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
    dataGridView1.Name = "dataGridView1";
    dataGridView1.Location = new Point(8, 8);
    dataGridView1.Size = new Size(500, 300);
    dataGridView1.AutoSizeRowsMode = 
        DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
    dataGridView1.ColumnHeadersBorderStyle = 
        DataGridViewHeaderBorderStyle.Raised;
    dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
    dataGridView1.GridColor = SystemColors.ActiveBorder;
    dataGridView1.RowHeadersVisible = false;

    dataGridView1.Columns[0].Name = "Release Date";
    dataGridView1.Columns[1].Name = "Track";
    dataGridView1.Columns[1].DefaultCellStyle.Alignment = 
        DataGridViewContentAlignment.MiddleCenter;
    dataGridView1.Columns[2].Name = "Title";
    dataGridView1.Columns[3].Name = "Artist";
    dataGridView1.Columns[4].Name = "Album";

    // Make the font italic for row four.
    dataGridView1.Columns[4].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Italic);

    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    dataGridView1.MultiSelect = false;

    dataGridView1.BackgroundColor = Color.Honeydew;

    dataGridView1.Dock = DockStyle.Fill;

    dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);
    dataGridView1.CellParsing += new DataGridViewCellParsingEventHandler(dataGridView1_CellParsing);
    addNewRowButton.Click += new EventHandler(addNewRowButton_Click);
    deleteRowButton.Click += new EventHandler(deleteRowButton_Click);
    ledgerStyleButton.Click += new EventHandler(ledgerStyleButton_Click);
    dataGridView1.CellValidating += new DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating);
}
Private Sub SetUpDataGridView()

    Me.Controls.Add(dataGridView1)
    dataGridView1.ColumnCount = 5

    With dataGridView1.ColumnHeadersDefaultCellStyle
        .BackColor = Color.Navy
        .ForeColor = Color.White
        .Font = New Font(dataGridView1.Font, FontStyle.Bold)
    End With

    With dataGridView1
        .EditMode = DataGridViewEditMode.EditOnEnter
        .Name = "dataGridView1"
        .Location = New Point(8, 8)
        .Size = New Size(500, 300)
        .AutoSizeRowsMode = _
            DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
        .ColumnHeadersBorderStyle = _
            DataGridViewHeaderBorderStyle.Raised
        .CellBorderStyle = _
            DataGridViewCellBorderStyle.Single
        .GridColor = SystemColors.ActiveBorder
        .RowHeadersVisible = False

        .Columns(0).Name = "Release Date"
        .Columns(1).Name = "Track"
        .Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        .Columns(2).Name = "Title"
        .Columns(3).Name = "Artist"
        .Columns(4).Name = "Album"

        ' Make the font italic for row four.
        .Columns(4).DefaultCellStyle.Font = _
            New Font(Control.DefaultFont, _
                FontStyle.Italic)

        .SelectionMode = _
            DataGridViewSelectionMode.FullRowSelect
        .MultiSelect = False

        .BackgroundColor = Color.Honeydew

        .Dock = DockStyle.Fill
    End With

End Sub

설명

이 속성에서 반환 되는 기본 DataGridViewCellStyle에는 다음과 같은 초기 속성 값이 있습니다.The default DataGridViewCellStyle returned by this property has the following initial property values:

DataGridViewCellStyle 속성DataGridViewCellStyle property 기본값Default value
BackColor SystemBrushes.Control 속성 값The value of the SystemBrushes.Control property.
ForeColor SystemBrushes.WindowText 속성 값The value of the SystemBrushes.WindowText property.
SelectionBackColor SystemBrushes.Highlight 속성 값The value of the SystemBrushes.Highlight property.
SelectionForeColor SystemBrushes.HighlightText 속성 값The value of the SystemBrushes.HighlightText property.
Font Font 속성 값The value of the Font property.
Alignment DataGridViewContentAlignment.MiddleLeft
WrapMode DataGridViewTriState.True

이러한 값은 DefaultCellStyle 속성을 통해 설정 된 값을 자동으로 재정의 합니다.These values automatically override the values set through the DefaultCellStyle property. 열 머리글이 DefaultCellStyle 값을 상속 하도록 하려면 ColumnHeadersDefaultCellStyle 개체의 값을 DataGridViewCellStyle 클래스에 대해 지정 된 기본값으로 설정 해야 합니다.To force column headers to inherit the DefaultCellStyle values, you must set the values in the ColumnHeadersDefaultCellStyle object to the default values indicated for the DataGridViewCellStyle class.

셀 스타일 상속에 대 한 자세한 내용은 Windows Forms DataGridView 컨트롤의 셀 스타일을 참조 하세요.For more information about cell style inheritance, see Cell Styles in the Windows Forms DataGridView Control.

비주얼 스타일을 사용 하 고 EnableHeadersVisualStyles true로 설정 하면 현재 테마를 사용 하 여 TopLeftHeaderCell를 제외한 모든 머리글 셀이 표시 되 고 ColumnHeadersDefaultCellStyle 값은 무시 됩니다.If visual styles are enabled and EnableHeadersVisualStyles is set to true, all header cells except the TopLeftHeaderCell are painted using the current theme and the ColumnHeadersDefaultCellStyle values are ignored.

적용 대상

추가 정보