DataGridTableStyle.GridColumnStyles Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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
Available since 1.1
Return to top
Show: