共用方式為


GridTableStylesCollection.Add(DataGridTableStyle) 方法

定義

DataGridTableStyle 新增至這個集合中。

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

參數

table
DataGridTableStyle

要加入至集合的 DataGridTableStyle

傳回

新加入物件的索引。

範例

下列程式碼範例會建立兩個 DataGridTableStyle 物件。 然後,此範例會建立數個 DataGridColumnStyle 物件,並將其新增至 GridColumnStylesCollection 。 最後, DataGridTableStyle 物件會使用 Add 方法新增至 GridTableStylesCollection

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

適用於