Condividi tramite


GridTableStylesCollection.Add(DataGridTableStyle) Metodo

Definizione

Aggiunge DataGridTableStyle a questa raccolta.

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

Parametri

table
DataGridTableStyle

Oggetto DataGridTableStyle da aggiungere alla raccolta.

Restituisce

Indice dell'oggetto appena aggiunto.

Esempio

Nell'esempio di codice seguente vengono creati due DataGridTableStyle oggetti. L'esempio crea quindi diversi DataGridColumnStyle oggetti e li aggiunge all'oggetto GridColumnStylesCollection. Infine, gli DataGridTableStyle oggetti vengono aggiunti all'uso GridTableStylesCollection del Add metodo .

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

Si applica a