DataGridTableStyle.GridColumnStyles Property

Definition

Gets the collection of columns drawn for this table.

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

Examples

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

private:
   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)
    {
        Console.WriteLine(dgt.MappingName);
        foreach(DataGridColumnStyle dgc in dgt.GridColumnStyles)
        {
            Console.WriteLine(dgc.MappingName);
        }
    }
}
Private Sub WriteMappingNames()
    Dim dgt As DataGridTableStyle
    For Each dgt In  myDataGrid.TableStyles
        Console.WriteLine(dgt.MappingName)
        Dim dgc As DataGridColumnStyle
        For Each dgc In  dgt.GridColumnStyles
            Console.WriteLine(dgc.MappingName)
        Next dgc
    Next dgt
End Sub

Remarks

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