Export (0) Print
Expand All

GridTableStylesCollection.Add Method

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
)

Parameters

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.
   myGridStyle.GridColumnStyles.Add(colStyle1);
   myGridStyle.GridColumnStyles.Add(colStyle2);   

   // Add the grid style to the GridStylesCollection.
   myDataGrid.TableStyles.Add(myGridStyle);
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft