DataGrid.TableStyles Propiedad

Definición

Obtiene la colección de objetos DataGridTableStyle de la cuadrícula.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

Valor de propiedad

GridTableStylesCollection que representa la colección de objetos DataGridTableStyle.A GridTableStylesCollection that represents the collection of DataGridTableStyle objects.

Ejemplos

En el ejemplo de código siguiente se crea un DataGridTableStyle para cada DataTable que se encuentra en un DataSet y se establece el MappingName de DataGridTableStyle en el TableName de DataTable.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. A continuación, se agrega el DataGridTableStyle al GridTableStylesCollection devuelto por la propiedad TableStyles.The DataGridTableStyle is then added to the GridTableStylesCollection returned by the TableStyles property. En el ejemplo también se imprime el MappingName de cada DataGridColumnStyle en la GridColumnStylesCollection devuelta por la propiedad GridColumnStyles de cada DataGridTableStyle en GridTableStylesCollection.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    

Comentarios

Use el GridTableStylesCollection recuperado a través de la propiedad TableStyles para crear vistas personalizadas de cada tabla mostrada por el control 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.

De forma predeterminada, la colección devuelta por @no__t propiedad-0 no contiene ningún objeto DataGridTableStyle.By default, the collection returned by TableStyles property does not contain any DataGridTableStyle objects. Para crear un conjunto de vistas personalizadas:To create a set of customized views:

  1. Creará un control DataGridTableStyle.Create a DataGridTableStyle.

  2. Establezca el MappingName del objeto de tabla de cuadrícula en el TableName del DataTable.Set the MappingName of the grid table object to the TableName of the DataTable.

  3. Agregue @no__t objetos-0, uno para cada columna de la cuadrícula que desee mostrar, al GridColumnStylesCollection devuelto por la propiedad GridColumnStyles.Add DataGridColumnStyle objects, one for each grid column you want to show, to the GridColumnStylesCollection returned by the GridColumnStyles property.

  4. Establezca el MappingName de cada DataGridColumnStyle en el @no__t 2 de un DataColumn.Set the MappingName of each DataGridColumnStyle to the ColumnName of a DataColumn.

  5. Agregue el objeto DataGridTableStyle a la colección devuelta por @no__t propiedad-1.Add the DataGridTableStyle object to the collection returned by TableStyles property.

Precaución

Cree siempre objetos DataGridColumnStyle y agréguelos al GridColumnStylesCollection antes de agregar objetos DataGridTableStyle a GridTableStylesCollection.Always create DataGridColumnStyle objects and add them to the GridColumnStylesCollection before adding DataGridTableStyle objects to the GridTableStylesCollection. Cuando se agrega un @no__t vacío-0 con un valor MappingName válido a la colección, se generan automáticamente los objetos DataGridColumnStyle.When you add an empty DataGridTableStyle with a valid MappingName value to the collection, DataGridColumnStyle objects are automatically generated for you. Por consiguiente, se producirá una excepción si intenta agregar nuevos objetos DataGridColumnStyle con valores duplicados de MappingName a la GridColumnStylesCollection.Consequently, an exception will be thrown if you try to add new DataGridColumnStyle objects with duplicate MappingName values to the GridColumnStylesCollection.

Se aplica a

Consulte también: