GridColumnStylesCollection Class

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

System.Object
  System.MarshalByRefObject
    System.Windows.Forms.BaseCollection
      System.Windows.Forms.GridColumnStylesCollection

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

[ListBindableAttribute(false)]
public class GridColumnStylesCollection : BaseCollection, 
	IList, ICollection, IEnumerable

The GridColumnStylesCollection type exposes the following members.

  NameDescription
Public propertyCountGets the total number of elements in the collection. (Inherited from BaseCollection.)
Public propertyIsReadOnlyGets a value indicating whether the collection is read-only. (Inherited from BaseCollection.)
Public propertyIsSynchronizedGets a value indicating whether access to the ICollection is synchronized. (Inherited from BaseCollection.)
Public propertyItem[Int32]Gets the DataGridColumnStyle at a specified index.
Public propertyItem[PropertyDescriptor]Gets the DataGridColumnStyle associated with the specified PropertyDescriptor.
Public propertyItem[String]Gets the DataGridColumnStyle with the specified name.
Protected propertyListGets the list of items in the collection. (Overrides BaseCollection.List.)
Public propertySyncRootGets an object that can be used to synchronize access to the BaseCollection. (Inherited from BaseCollection.)
Top

  NameDescription
Public methodAddAdds a column style to the collection.
Public methodAddRangeAdds an array of column style objects to the collection.
Public methodClearClears the collection of DataGridColumnStyle objects.
Public methodContains(DataGridColumnStyle)Gets a value indicating whether the GridColumnStylesCollection contains the specified DataGridColumnStyle.
Public methodContains(PropertyDescriptor)Gets a value indicating whether the GridColumnStylesCollection contains a DataGridColumnStyle associated with the specified PropertyDescriptor.
Public methodContains(String)Gets a value indicating whether the GridColumnStylesCollection contains the DataGridColumnStyle with the specified name.
Public methodCopyToCopies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index. (Inherited from BaseCollection.)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetEnumeratorGets the object that enables iterating through the members of the collection. (Inherited from BaseCollection.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOfGets the index of a specified DataGridColumnStyle.
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected methodOnCollectionChangedRaises the CollectionChanged event.
Public methodRemoveRemoves the specified DataGridColumnStyle from the GridColumnStylesCollection.
Public methodRemoveAtRemoves the DataGridColumnStyle with the specified index from the GridColumnStylesCollection.
Public methodResetPropertyDescriptorsSets the PropertyDescriptor for each column style in the collection to null.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventCollectionChangedOccurs when a change is made to the GridColumnStylesCollection.
Top

  NameDescription
Public Extension MethodAsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodCast<TResult>Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top

  NameDescription
Explicit interface implemetationPrivate methodICollection.CopyToInfrastructure. Copies the collection to a compatible one-dimensional Array, starting at the specified index of the target array.
Explicit interface implemetationPrivate propertyICollection.CountInfrastructure. Gets the number of elements contained in the collection.
Explicit interface implemetationPrivate propertyICollection.IsSynchronizedInfrastructure. Gets a value indicating whether access to the GridColumnStylesCollection is synchronized (thread safe).
Explicit interface implemetationPrivate propertyICollection.SyncRootInfrastructure. Gets an object that can be used to synchronize access to the GridColumnStylesCollection.
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorInfrastructure. Returns an enumerator for the collection.
Explicit interface implemetationPrivate methodIList.AddInfrastructure. Adds an object to the collection.
Explicit interface implemetationPrivate methodIList.ClearInfrastructure. Clears the collection of DataGridColumnStyle objects.
Explicit interface implemetationPrivate methodIList.ContainsInfrastructure. Determines whether an element is in the collection.
Explicit interface implemetationPrivate methodIList.IndexOfInfrastructure. Returns the zero-based index of the first occurrence of the specified object in the collection.
Explicit interface implemetationPrivate methodIList.InsertInfrastructure. This method is not supported by this control.
Explicit interface implemetationPrivate propertyIList.IsFixedSizeInfrastructure. Gets a value indicating whether the collection has a fixed size.
Explicit interface implemetationPrivate propertyIList.IsReadOnlyInfrastructure. Gets a value indicating whether the collection is read-only.
Explicit interface implemetationPrivate propertyIList.ItemInfrastructure. Gets the element at the specified index.
Explicit interface implemetationPrivate methodIList.RemoveInfrastructure. Removes the specified DataGridColumnStyle from the GridColumnStylesCollection.
Explicit interface implemetationPrivate methodIList.RemoveAtInfrastructure. Removes the DataGridColumnStyle at the specified index from the GridColumnStylesCollection.
Top

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

.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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft