DataGridTableStyle.GridColumnStyles Property


Gets the collection of columns drawn for this table.

 virtual property System::Windows::Forms::GridColumnStylesCollection ^ GridColumnStyles { System::Windows::Forms::GridColumnStylesCollection ^ get(); };
public virtual System.Windows.Forms.GridColumnStylesCollection GridColumnStyles { get; }
member this.GridColumnStyles : System.Windows.Forms.GridColumnStylesCollection
Public Overridable ReadOnly Property GridColumnStyles As GridColumnStylesCollection

Property Value


A GridColumnStylesCollection that contains all DataGridColumnStyle objects for the table.


The following code example gets the GridColumnStylesCollection of a DataGridTableStyle and prints each object's header.

   void WriteMappingNames()
      for each ( DataGridTableStyle^ dgt in myDataGrid->TableStyles )
         Console::WriteLine( dgt->MappingName );
         for each ( DataGridColumnStyle^ dgc in dgt->GridColumnStyles )
            Console::WriteLine( dgc->MappingName );
private void WriteMappingNames(){
    foreach(DataGridTableStyle dgt in myDataGrid.TableStyles)
        foreach(DataGridColumnStyle dgc in dgt.GridColumnStyles)
Private Sub WriteMappingNames()
    Dim dgt As DataGridTableStyle
    For Each dgt In  myDataGrid.TableStyles
        Dim dgc As DataGridColumnStyle
        For Each dgc In  dgt.GridColumnStyles
        Next dgc
    Next dgt
End Sub


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.

Applies to