Export (0) Print
Expand All

DataGridTableStyle.GridColumnStyles Property

Gets the collection of columns drawn for this table.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public virtual GridColumnStylesCollection GridColumnStyles { get; }

Property Value

Type: System.Windows.Forms.GridColumnStylesCollection
A GridColumnStylesCollection that contains all DataGridColumnStyle objects for the table.

The GridColumnStylesCollection returned by the GridColumnStyles property allows you to create a customized set of column styles. For each DataColumn in a DataTable, set the MappingName of a DataGridColumnStyle to the ColumnName. That column style will automatically be used when this DataGridTableStyle is displayed.

If you create a DataGridTableStyle without adding any DataGridColumnStyle objects to the GridColumnStylesCollection, a collection of DataGridColumnStyle objects will be created automatically when a DataGridTableStyle with a valid MappingName is added to the GridTableStylesCollection. An exception will be thrown if you attempt to add DataGridColumnStyle objects with duplicate MappingName values to the collection.

The following code example gets the GridColumnStylesCollection of a DataGridTableStyle and prints each object's header.

private void WriteMappingNames(){
    foreach(DataGridTableStyle dgt in myDataGrid.TableStyles)
    {
        Console.WriteLine(dgt.MappingName);
        foreach(DataGridColumnStyle dgc in dgt.GridColumnStyles)
        {
            Console.WriteLine(dgc.MappingName);
        }
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft