DataGridView.ColumnHeadersDefaultCellStyle 속성

정의

기본 열 머리글 스타일을 가져오거나 설정합니다.

public System.Windows.Forms.DataGridViewCellStyle ColumnHeadersDefaultCellStyle { get; set; }

속성 값

기본 열 머리글 스타일을 나타내는 DataGridViewCellStyle입니다.

예제

다음 코드 예제에서는 설정 ColumnHeadersDefaultCellStyle하는 방법을 보여 줍니다., , AutoSizeRowsMode, ColumnHeadersBorderStyle, GridColorCellBorderStyle, , BackgroundColor, , RowHeadersVisibleSelectionMode, ColumnCount, 및 MultiSelect 속성입니다. 또한 코드 예제를 설정 하는 방법을 보여 줍니다는 DataGridViewColumn.NameDataGridViewColumn.DefaultCellStyle 속성입니다. 이 예제를 실행하려면 라는 가 포함된 DataGridView 폼에 코드를 붙여넣은 다음 폼의 생성자 또는 Load 이벤트 처리기에서 메서드를 호출 SetUpDataGridViewdataGridView1합니다. 모든 이벤트가 해당 이벤트 처리기와 연결되어 있는지 확인합니다.

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);
}

설명

이 속성에서 반환되는 기본값 DataGridViewCellStyle 에는 다음과 같은 초기 속성 값이 있습니다.

이러한 값은 속성을 통해 설정된 값을 자동으로 재정의합니다 DefaultCellStyle . 열 머리글이 값을 상속 DefaultCellStyle 하도록 하려면 개체의 값을 클래스에 ColumnHeadersDefaultCellStyle 대해 표시된 DataGridViewCellStyle 기본값으로 설정해야 합니다.

셀 스타일 상속에 대한 자세한 내용은 Windows Forms DataGridView 컨트롤의 셀 스타일을 참조하세요.

비주얼 스타일을 사용하고 EnableHeadersVisualStyles 로 설정된 true경우 를 제외한 TopLeftHeaderCell 모든 머리글 셀은 현재 테마를 사용하여 그려지고 ColumnHeadersDefaultCellStyle 값은 무시됩니다.

적용 대상

제품 버전
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

추가 정보