GridTableStylesCollection.Add(DataGridTableStyle) Methode

Definition

Fügt dieser Auflistung einen DataGridTableStyle hinzu.

public:
 virtual int Add(System::Windows::Forms::DataGridTableStyle ^ table);
public virtual int Add (System.Windows.Forms.DataGridTableStyle table);
abstract member Add : System.Windows.Forms.DataGridTableStyle -> int
override this.Add : System.Windows.Forms.DataGridTableStyle -> int
Public Overridable Function Add (table As DataGridTableStyle) As Integer

Parameter

table
DataGridTableStyle

Der der Auflistung hinzuzufügende DataGridTableStyle.

Gibt zurück

Int32

Der Index des neu hinzugefügten Objekts.

Beispiele

Im folgenden Codebeispiel werden zwei DataGridTableStyle Objekte erstellt. Das Beispiel erstellt dann mehrere DataGridColumnStyle Objekte und fügt sie dem GridColumnStylesCollection. Schließlich werden die DataGridTableStyle Objekte zur Verwendung der GridTableStylesCollection Add Methode hinzugefügt.

void AddDataGridTableStyle()
{
   // Create a new DataGridTableStyle and set MappingName.
   DataGridTableStyle^ myGridStyle = gcnew DataGridTableStyle;
   myGridStyle->MappingName = "Customers";
   
   // Create two DataGridColumnStyle objects.
   DataGridColumnStyle^ colStyle1 = gcnew DataGridTextBoxColumn;
   colStyle1->MappingName = "firstName";
   DataGridColumnStyle^ colStyle2 = gcnew 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 );
}
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);
}
Private Sub AddDataGridTableStyle()
   ' Create a new DataGridTableStyle and set MappingName.
   Dim myGridStyle As DataGridTableStyle = _
   new DataGridTableStyle()
   myGridStyle.MappingName = "Customers"

   ' Add two DataGridColumnStyle objects.
   Dim colStyle1 As DataGridColumnStyle = _
   new DataGridTextBoxColumn()
   colStyle1.MappingName = "firstName"
   
   Dim colStyle2 As DataGridColumnStyle = _
   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)
End Sub

Gilt für