GridTableStylesCollection.Add(DataGridTableStyle) Method

Definition

Adds a DataGridTableStyle to this collection.

C#
public virtual int Add(System.Windows.Forms.DataGridTableStyle table);

Parameters

table
DataGridTableStyle

The DataGridTableStyle to add to the collection.

Returns

The index of the newly added object.

Examples

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.

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

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 10