GridTableStylesCollection.Add(DataGridTableStyle) Metoda

Definicja

Dodaje element DataGridTableStyle do tej kolekcji.

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

Parametry

table
DataGridTableStyle

Element DataGridTableStyle do dodania do kolekcji.

Zwraca

Indeks nowo dodanego obiektu.

Przykłady

Poniższy przykład kodu tworzy dwa DataGridTableStyle obiekty. Następnie przykład tworzy kilka DataGridColumnStyle obiektów i dodaje je do obiektu GridColumnStylesCollection. DataGridTableStyle Na koniec obiekty są dodawane do GridTableStylesCollection metody przy użyciu Add metody .

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

Dotyczy

Produkt Wersje
.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