GridColumnStylesCollection Class

Represents a collection of DataGridColumnStyle objects in the System.Windows.Forms.DataGrid control.

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

Public Class GridColumnStylesCollection
	Inherits BaseCollection
	Implements IList, ICollection, IEnumerable
Dim instance As GridColumnStylesCollection

public class GridColumnStylesCollection extends BaseCollection implements IList, ICollection, 
public class GridColumnStylesCollection extends BaseCollection implements IList, ICollection, 
Not applicable.

On the DataGridTableStyle, you access the GridColumnStylesCollection through the GridColumnStyles property.

The GridColumnStylesCollection uses standard Add and Remove methods to manipulate the collection.

Use the Contains method to determine if a specific property value exists in the collection. Additionally, use the IndexOf method to determine the index of any DataGridColumnStyle object within the collection.

Caution noteCaution:

Always create DataGridColumnStyle objects and add them to the GridColumnStylesCollection before adding DataGridTableStyle objects to the GridTableStylesCollection. When you add an empty DataGridTableStyle with a valid MappingName value to the collection, DataGridColumnStyle objects are automatically generated for you. Consequently, an exception will be thrown if you try to add new DataGridColumnStyle objects with duplicate MappingName values to the GridColumnStylesCollection.

The following code example prints information about each DataGridColumnStyle in a GridColumnStylesCollection.

Private Sub PrintColumnInformation(grid as DataGrid)
   Console.WriteLine("Count: " & grid.TableStyles.Count)
   Dim myTableStyle As DataGridTableStyle
   Dim myColumns As GridColumnStylesCollection
   Dim dgCol As DataGridColumnStyle
   For Each myTableStyle in grid.TableStyles
      myColumns = myTableStyle.GridColumnStyles
      ' Iterate through the collection and print each 
      ' object's type and width.
      For Each dgCol in myColumns
End Sub

private void PrintColumnInformation(DataGrid grid)
    Console.WriteLine(("Count: " + grid.get_TableStyles().get_Count()));
    GridColumnStylesCollection myColumns;
    for (int iCtr = 0; iCtr < grid.get_TableStyles().get_Count(); 
            iCtr++) {
        DataGridTableStyle myTableStyle = 
        myColumns = myTableStyle.get_GridColumnStyles();

        /* Iterate through the collection and print each 
         * object's type and width. 
        for (int iCtr1 = 0; iCtr1 < myColumns.get_Count(); iCtr1++) {
            DataGridColumnStyle dgCol = myColumns.get_Item(iCtr1);
} //PrintColumnInformation

function PrintColumnInformation(grid: DataGrid){
   Console.WriteLine("Count: " + grid.TableStyles.Count);
   var myColumns: GridColumnStylesCollection;   
   for(var myTableStyle in grid.TableStyles){

      myColumns = myTableStyle.GridColumnStyles;

      // Iterate through the collection and print each
      // object's type and width.
      for (var dgCol in myColumns){


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions