GridTableStylesCollection.Add Method (DataGridTableStyle)


Adds a DataGridTableStyle to this collection.

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

public virtual int Add(
	DataGridTableStyle table


Type: System.Windows.Forms.DataGridTableStyle

The DataGridTableStyle to add to the collection.

Return Value

Type: System.Int32

The index of the newly added object.

The following code example creates two DataGridTableStyle objects. The example then creates several DataGridColumnStyle objects and adds them to the GridColumnStylesCollection. Finally, the DataGridTableStyle objects are added to the GridTableStylesCollection using the Add method.

private void AddDataGridTableStyle()
   // Create a new DataGridTableStyle and set MappingName.
   DataGridTableStyle myGridStyle = 
   new DataGridTableStyle();
   myGridStyle.MappingName = "Customers";

   // Create two DataGridColumnStyle objects.
   DataGridColumnStyle colStyle1 =
   new DataGridTextBoxColumn();
   colStyle1.MappingName = "firstName";

   DataGridColumnStyle colStyle2 =
   new DataGridBoolColumn();
   colStyle2.MappingName = "Current";

   // Add column styles to table style.

   // Add the grid style to the GridStylesCollection.

.NET Framework
Available since 1.1
Return to top