Export (0) Print
Expand All

GridColumnStylesCollection Class

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

For a list of all members of this type, see GridColumnStylesCollection Members.

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

[Visual Basic]
Public Class GridColumnStylesCollection
   Inherits BaseCollection
   Implements IList
[C#]
public class GridColumnStylesCollection : BaseCollection, IList
[C++]
public __gc class GridColumnStylesCollection : public
   BaseCollection, IList
[JScript]
public class GridColumnStylesCollection extends BaseCollection
   implements IList

Thread Safety

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

Remarks

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   Always create DataGridColumnStyle objects and add them to the GridColumnStylesCollection before adding DataGridTableStyle objects to the GridTableStylesCollection. When you add an empty DataGridTableStyle 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.

Example

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

[Visual Basic] 
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
         Console.WriteLine(dgCol.MappingName)
         Console.WriteLine(dgCol.GetType.ToString())
         Console.WriteLine(dgCol.Width)
      Next
   Next
End Sub

[C#] 
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);
      }
   }
}

[C++] 
private:
   void PrintColumnInformation(DataGrid *grid) {
      Console::WriteLine(S"Count: {0}", __box(grid->TableStyles->Count));
      GridColumnStylesCollection __gc *myColumns;   
      DataGridTableStyle __gc *myTableStyle;
      for (__int32 i=0; i < grid->TableStyles->Count; i++) { 
         myTableStyle = grid->TableStyles->Item[i];
         myColumns = myTableStyle->GridColumnStyles;

         /* Iterate through the collection and print each 
         object's type and width. */
         DataGridColumnStyle __gc *dgCol;
         for (__int32 j=0; j < myColumns->Count; j++) {  
            dgCol = myColumns->Item[j];
            Console::WriteLine(dgCol->MappingName);
            Console::WriteLine(dgCol->GetType()->ToString());
            Console::WriteLine(dgCol->Width);
         }
      }
   };

[JScript] 
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);
      }
   }
}

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

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

See Also

GridColumnStylesCollection Members | System.Windows.Forms Namespace | Add | DataColumn | DataGrid | DataGridBoolColumn | DataGridColumnStyle | GridColumnStylesCollection | DataGridTextBoxColumn | Remove

Show:
© 2014 Microsoft