DataGrid.TableStyles DataGrid.TableStyles DataGrid.TableStyles DataGrid.TableStyles Property

정의

표의 DataGridTableStyle 개체 컬렉션을 가져옵니다.Gets the collection of DataGridTableStyle objects for the grid.

public:
 property System::Windows::Forms::GridTableStylesCollection ^ TableStyles { System::Windows::Forms::GridTableStylesCollection ^ get(); };
public System.Windows.Forms.GridTableStylesCollection TableStyles { get; }
member this.TableStyles : System.Windows.Forms.GridTableStylesCollection
Public ReadOnly Property TableStyles As GridTableStylesCollection

속성 값

예제

다음 코드 예제에서는 하나 DataGridTableStyle 각각에 대 한 DataTable 있는 DataSet, 설정 및를 MappingNameDataGridTableStyleTableNameDataTable합니다.The following code example creates one DataGridTableStyle for each DataTable found in a DataSet, and sets the MappingName of the DataGridTableStyle to the TableName of the DataTable. DataGridTableStyle 에 추가 되는 GridTableStylesCollection 반환한는 TableStyles 속성입니다.The DataGridTableStyle is then added to the GridTableStylesCollection returned by the TableStyles property. 또한 출력 합니다는 MappingNameDataGridColumnStyleGridColumnStylesCollection 반환한를 GridColumnStyles 각 속성 DataGridTableStyleGridTableStylesCollection.The example also prints the MappingName of each DataGridColumnStyle in the GridColumnStylesCollection returned by the GridColumnStyles property of each DataGridTableStyle in the GridTableStylesCollection.

private:
   void AddTables( DataGrid^ myDataGrid, DataSet^ myDataSet )
   {
      for each ( DataTable^ t in myDataSet->Tables )
      {
         DataGridTableStyle^ myGridTableStyle =
            gcnew DataGridTableStyle;
         myGridTableStyle->MappingName = t->TableName;
         myDataGrid->TableStyles->Add( myGridTableStyle );
         
         /* Note that DataGridColumnStyle objects will
            be created automatically for the first DataGridTableStyle
            when you add it to the GridTableStylesCollection.*/
      }
   }

   void PrintGridStyleInfo( DataGrid^ myDataGrid )
   {
      /* Print the MappingName of each DataGridTableStyle,
         and the MappingName of each DataGridColumnStyle. */
      for each ( DataGridTableStyle^ myGridStyle in
         myDataGrid->TableStyles )
      {
         Console::WriteLine( myGridStyle->MappingName );
         for each ( DataGridColumnStyle^ myColumnStyle in
            myGridStyle->GridColumnStyles )
         {
            Console::WriteLine( myColumnStyle->MappingName );
         }
      }
   }
private void AddTables(DataGrid myDataGrid, DataSet myDataSet){
   foreach(DataTable t in myDataSet.Tables){
      DataGridTableStyle myGridTableStyle = new 
      DataGridTableStyle();
      myGridTableStyle.MappingName = t.TableName;
      myDataGrid.TableStyles.Add(myGridTableStyle);

      /* Note that DataGridColumnStyle objects will
      be created automatically for the first DataGridTableStyle
      when you add it to the GridTableStylesCollection.*/
   }
}
private void PrintGridStyleInfo(DataGrid myDataGrid){
   /* Print the MappingName of each DataGridTableStyle,
   and the MappingName of each DataGridColumnStyle. */
   foreach(DataGridTableStyle myGridStyle in 
   myDataGrid.TableStyles){
   Console.WriteLine(myGridStyle.MappingName);
   foreach(DataGridColumnStyle myColumnStyle in 
      myGridStyle.GridColumnStyles){
	 Console.WriteLine(myColumnStyle.MappingName);
      }
   }
}
 
Private Sub AddTables(myDataGrid As DataGrid, _
myDataSet As DataSet )
    Dim t As DataTable 
    For Each t in myDataSet.Tables
       Dim myGridTableStyle As DataGridTableStyle  = new _
       DataGridTableStyle()
 	     myGridTableStyle.MappingName = t.TableName
 	     myDataGrid.TableStyles.Add(myGridTableStyle)
       ' Note that DataGridColumnStyle objects will
       ' be created automatically for the first DataGridTableStyle
       ' when you add it to the GridTableStylesCollection.*/
    Next
 End Sub
 Private Sub PrintGridStyleInfo(myDataGrid As DataGrid )
    Dim myGridStyle As DataGridTableStyle
    Dim myColumnStyle As DataGridColumnStyle
    
    for each myGridStyle in _
    myDataGrid.TableStyles
       Console.WriteLine(myGridStyle.MappingName)
       for each myColumnStyle in myGridStyle.GridColumnStyles
 	    Console.WriteLine(myColumnStyle.MappingName)
       Next
    Next
 End Sub    

설명

사용 하 여는 GridTableStylesCollection 검색할 합니다 TableStyles 속성으로 표시 하는 각 테이블의 사용자 지정된 보기를 만들 수는 System.Windows.Forms.DataGrid 컨트롤입니다.Use the GridTableStylesCollection retrieved through the TableStyles property to create customized views of each table displayed by the System.Windows.Forms.DataGrid control.

기본적으로 반환한 컬렉션이 TableStyles 속성을 포함 하지 DataGridTableStyle 개체입니다.By default, the collection returned by TableStyles property does not contain any DataGridTableStyle objects. 사용자 지정된 뷰 집합을 만들려면:To create a set of customized views:

  1. DataGridTableStyle를 만듭니다.Create a DataGridTableStyle.

  2. 설정 합니다 MappingName 모눈 표 개체의는 TableNameDataTable합니다.Set the MappingName of the grid table object to the TableName of the DataTable.

  3. 추가 DataGridColumnStyle 개체를 표시 하려는 각 표 형태 창의 열에 대 한 합니다 GridColumnStylesCollection 반환한는 GridColumnStyles 속성입니다.Add DataGridColumnStyle objects, one for each grid column you want to show, to the GridColumnStylesCollection returned by the GridColumnStyles property.

  4. 설정 합니다 MappingNameDataGridColumnStyleColumnNameDataColumn합니다.Set the MappingName of each DataGridColumnStyle to the ColumnName of a DataColumn.

  5. 추가 된 DataGridTableStyle 개체를 반환 하는 컬렉션 TableStyles 속성입니다.Add the DataGridTableStyle object to the collection returned by TableStyles property.

주의

항상 만들기 DataGridColumnStyle 개체에 추가 하는 GridColumnStylesCollection 추가 하기 전에 DataGridTableStyle 개체는 GridTableStylesCollection합니다.Always create DataGridColumnStyle objects and add them to the GridColumnStylesCollection before adding DataGridTableStyle objects to the GridTableStylesCollection. 빈을 추가 하는 경우 DataGridTableStyle 을 올바른 MappingName 컬렉션에 값 DataGridColumnStyle 개체를 자동으로 생성 됩니다.When you add an empty DataGridTableStyle with a valid MappingName value to the collection, DataGridColumnStyle objects are automatically generated for you. 새로 추가 하려고 하면 예외가 throw 될 따라서 DataGridColumnStyle 중복을 사용 하 여 개체 MappingName 값을 GridColumnStylesCollection입니다.Consequently, an exception will be thrown if you try to add new DataGridColumnStyle objects with duplicate MappingName values to the GridColumnStylesCollection.

적용 대상

추가 정보