Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

GridColumnStylesCollection Class

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

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

public class GridColumnStylesCollection : BaseCollection, IList, ICollection, IEnumerable
public class GridColumnStylesCollection extends BaseCollection implements IList, ICollection, 
	IEnumerable
public class GridColumnStylesCollection extends BaseCollection implements IList, ICollection, 
	IEnumerable

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 void PrintColumnInformation(DataGrid grid){
   Console.WriteLine("Count: " + grid.TableStyles.Count);
   GridColumnStylesCollection myColumns;   
   foreach(DataGridTableStyle myTableStyle in grid.TableStyles){

      myColumns = myTableStyle.GridColumnStyles;

      /* Iterate through the collection and print each 
      object's type and width. */
      foreach (DataGridColumnStyle dgCol in myColumns){
         Console.WriteLine(dgCol.MappingName);
         Console.WriteLine(dgCol.GetType().ToString());
         Console.WriteLine(dgCol.Width);
      }
   }
}

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 = 
            grid.get_TableStyles().get_Item(iCtr);
        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);
            Console.WriteLine(dgCol.get_MappingName());
            Console.WriteLine(dgCol.GetType().ToString());
            Console.WriteLine(dgCol.get_Width());
        }
    }
} //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){
         Console.WriteLine(dgCol.MappingName);
         Console.WriteLine(dgCol.GetType().ToString());
         Console.WriteLine(dgCol.Width);
      }
   }
}

System.Object
   System.MarshalByRefObject
     System.Windows.Forms.BaseCollection
      System.Windows.Forms.GridColumnStylesCollection
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 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:
© 2014 Microsoft. All rights reserved.