GridColumnStyles Property

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)

[LocalizableAttribute(true)] 
public virtual GridColumnStylesCollection GridColumnStyles { get; }
/** @property */
public GridColumnStylesCollection get_GridColumnStyles ()

public function get GridColumnStyles () : GridColumnStylesCollection

Property Value

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

private void WriteMappingNames()
{
    DataGridTableStyle dgt;
    for (int iCtr = 0; iCtr < myDataGrid.get_TableStyles().get_Count(); 
        iCtr++) {
        dgt = myDataGrid.get_TableStyles().get_Item(iCtr);
        Console.WriteLine(dgt.get_MappingName());
        DataGridColumnStyle dgc;
        for (int iCtr1 = 0; iCtr1 < dgt.get_GridColumnStyles().get_Count(); 
            iCtr1++) {
            dgc = dgt.get_GridColumnStyles().get_Item(iCtr1);
            Console.WriteLine(dgc.get_MappingName());
        }
    }
} //WriteMappingNames

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, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2016 Microsoft