DataGridViewButtonColumn.DefaultCellStyle 属性

定义

获取或设置列的默认单元格样式。

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; }
[<System.ComponentModel.Browsable(true)>]
member this.DefaultCellStyle : System.Windows.Forms.DataGridViewCellStyle with get, set
Public Overrides Property DefaultCellStyle As DataGridViewCellStyle

属性值

DataGridViewCellStyle

作为默认样式应用的 DataGridViewCellStyle

属性

示例

下面的代码示例演示了此属性的使用。

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

注解

此属性返回的默认DataGridViewCellStyle属性值为 MiddleCenter.Alignment 此值替代控件属性DataGridView中指定的DefaultCellStyle值,但可能被其他单元格样式属性重写。 有关详细信息,请参阅 Windows 窗体 DataGridView 控件中的单元格样式

备注

启用视觉样式后,按钮列中的按钮使用 ButtonRenderer 通过属性指定的单元格样式进行绘制,例如 DefaultCellStyle 没有效果。

适用于

另请参阅