Export (0) Print
Expand All

DataGridViewButtonColumn.DefaultCellStyle Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the column's default cell style.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public override DataGridViewCellStyle DefaultCellStyle { get; set; }
/** @property */
public DataGridViewCellStyle get_DefaultCellStyle ()

/** @property */
public void set_DefaultCellStyle (DataGridViewCellStyle value)

public override function get DefaultCellStyle () : DataGridViewCellStyle

public override function set DefaultCellStyle (value : DataGridViewCellStyle)

Property Value

The DataGridViewCellStyle to be applied as the default style.

The default DataGridViewCellStyle returned by this property has an initial Alignment property value of MiddleCenter. This value overrides the value specified in the DefaultCellStyle property of the DataGridView control, but may be overridden by other cell style properties. For more information, see Cell Styles in the Windows Forms DataGridView Control.

NoteNote

When visual styles are enabled, the buttons in a button column are painted using a ButtonRenderer and cell styles specified through properties such as DefaultCellStyle have no effect.

The following code example demonstrates the use of this property.

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 void ChangeColumnAlignment()
{
    songsDataGridView.get_Columns().get_Item("Title").get_DefaultCellStyle().
        set_Alignment(DataGridViewContentAlignment.BottomCenter);
    songsDataGridView.get_Columns().get_Item("Title").
        set_Name(DataGridViewContentAlignment.BottomCenter.ToString());

    songsDataGridView.get_Columns().get_Item("Artist").
        get_DefaultCellStyle().set_Alignment(DataGridViewContentAlignment.
        BottomLeft);
    songsDataGridView.get_Columns().get_Item("Artist").set_Name(
        DataGridViewContentAlignment.BottomLeft.ToString());

    songsDataGridView.get_Columns().get_Item("Album").
        get_DefaultCellStyle().set_Alignment(DataGridViewContentAlignment.
        BottomRight);
    songsDataGridView.get_Columns().get_Item("Album").set_Name(
        DataGridViewContentAlignment.BottomRight.ToString());

    songsDataGridView.get_Columns().get_Item("Release Date").
        get_DefaultCellStyle().set_Alignment(DataGridViewContentAlignment.
        MiddleCenter);
    songsDataGridView.get_Columns().get_Item("Release Date").set_Name(
        DataGridViewContentAlignment.MiddleCenter.ToString());

    songsDataGridView.get_Columns().get_Item("Track").
        get_DefaultCellStyle().set_Alignment(DataGridViewContentAlignment.
        MiddleLeft);
    songsDataGridView.get_Columns().get_Item("Track").set_Name(
        DataGridViewContentAlignment.MiddleLeft.ToString());
} //ChangeColumnAlignment

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft