DataGridViewColumn.DefaultCellStyle 속성

정의

열의 기본 셀 스타일을 가져오거나 설정합니다.Gets or sets the column's default cell style.

public:
 virtual property System::Windows::Forms::DataGridViewCellStyle ^ DefaultCellStyle { System::Windows::Forms::DataGridViewCellStyle ^ get(); void set(System::Windows::Forms::DataGridViewCellStyle ^ value); };
[System.ComponentModel.Browsable(true)]
public override System.Windows.Forms.DataGridViewCellStyle DefaultCellStyle { get; set; }
member this.DefaultCellStyle : System.Windows.Forms.DataGridViewCellStyle with get, set
Public Overrides Property DefaultCellStyle As DataGridViewCellStyle

속성 값

열의 기본 셀 스타일을 나타내는 DataGridViewCellStyle입니다.A DataGridViewCellStyle that represents the default style of the cells in the column.

특성

예제

다음 코드 예제에서는 DefaultCellStyle 속성을 사용 하 여 다양 한 열의 콘텐츠 맞춤을 설정 합니다.The following code example uses the DefaultCellStyle property to set the content alignment of various columns.

private void ChangeColumnAlignment()
{
    songsDataGridView.Columns["Title"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter;
    songsDataGridView.Columns["Title"].Name = DataGridViewContentAlignment.BottomCenter.ToString();

    songsDataGridView.Columns["Artist"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomLeft;
    songsDataGridView.Columns["Artist"].Name = DataGridViewContentAlignment.BottomLeft.ToString();

    songsDataGridView.Columns["Album"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;
    songsDataGridView.Columns["Album"].Name = DataGridViewContentAlignment.BottomRight.ToString();

    songsDataGridView.Columns["Release Date"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
    songsDataGridView.Columns["Release Date"].Name = DataGridViewContentAlignment.MiddleCenter.ToString();

    songsDataGridView.Columns["Track"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
    songsDataGridView.Columns["Track"].Name = DataGridViewContentAlignment.MiddleLeft.ToString();
}
Private Sub ChangeColumnAlignment()
    songsDataGridView.Columns("Title").DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter
    songsDataGridView.Columns("Title").Name = DataGridViewContentAlignment.BottomCenter.ToString()

    songsDataGridView.Columns("Artist").DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomLeft
    songsDataGridView.Columns("Artist").Name = DataGridViewContentAlignment.BottomLeft.ToString()

    songsDataGridView.Columns("Album").DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight
    songsDataGridView.Columns("Album").Name = DataGridViewContentAlignment.BottomRight.ToString()

    songsDataGridView.Columns("Release Date").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
    songsDataGridView.Columns("Release Date").Name = DataGridViewContentAlignment.MiddleCenter.ToString()

    songsDataGridView.Columns("Track").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
    songsDataGridView.Columns("Track").Name = DataGridViewContentAlignment.MiddleLeft.ToString()
End Sub

설명

DataGridView 컨트롤은 DataGridViewCellStyle형식의 다른 속성에서 스타일을 상속 하는 셀 InheritedStyle 속성으로 표시 되는 스타일을 사용 하 여 셀을 표시 합니다.The DataGridView control displays its cells using the styles indicated by the cell InheritedStyle property, which inherits styles from other properties of type DataGridViewCellStyle. 이 열에 있는 셀의 경우 DefaultCellStyle 속성을 통해 지정 된 스타일은 DataGridView.DefaultCellStyle 속성을 통해 지정 된 스타일을 재정의 하지만 DataGridView.RowsDefaultCellStyle, DataGridView.AlternatingRowsDefaultCellStyle, DataGridViewRow.DefaultCellStyleDataGridViewCell.Style 속성을 통해 지정 된 스타일에 의해 재정의 됩니다.For cells in this column, the styles specified through the DefaultCellStyle property override the styles specified through the DataGridView.DefaultCellStyle property, but are overridden by the styles specified through the DataGridView.RowsDefaultCellStyle, DataGridView.AlternatingRowsDefaultCellStyle, DataGridViewRow.DefaultCellStyle, and DataGridViewCell.Style properties.

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

적용 대상

추가 정보