GridTableStylesCollection GridTableStylesCollection GridTableStylesCollection GridTableStylesCollection Class

Definição

Representa uma coleção de objetos DataGridTableStyle no controle DataGrid.Represents a collection of DataGridTableStyle objects in the DataGrid control.

public ref class GridTableStylesCollection : System::Windows::Forms::BaseCollection, System::Collections::IList
[System.ComponentModel.ListBindable(false)]
public class GridTableStylesCollection : System.Windows.Forms.BaseCollection, System.Collections.IList
type GridTableStylesCollection = class
    inherit BaseCollection
    interface IList
    interface ICollection
    interface IEnumerable
Public Class GridTableStylesCollection
Inherits BaseCollection
Implements IList
Herança
GridTableStylesCollectionGridTableStylesCollectionGridTableStylesCollectionGridTableStylesCollection
Atributos
Implementações

Exemplos

O exemplo de código a seguir DataGridTableStyle cria dois objetos e adiciona cada GridTableStylesCollection um ao retornado TableStyles pela propriedade de DataGrid um controle.The following code example creates two DataGridTableStyle objects and adds each to the GridTableStylesCollection returned by the TableStyles property of a DataGrid control.

void AddCustomDataTableStyle()
{
   DataGridTableStyle^ ts1 = gcnew DataGridTableStyle;
   ts1->MappingName = "Customers";
   
   // Set other properties.
   ts1->AlternatingBackColor = Color::LightGray;
   
   /* Add a GridColumnStyle and set its MappingName
     to the name of a DataColumn in the DataTable.
     Set the HeaderText and Width properties. */
   DataGridColumnStyle^ boolCol = gcnew DataGridBoolColumn;
   boolCol->MappingName = "Current";
   boolCol->HeaderText = "IsCurrent Customer";
   boolCol->Width = 150;
   ts1->GridColumnStyles->Add( boolCol );
   
   // Add a second column style.
   DataGridColumnStyle^ TextCol = gcnew DataGridTextBoxColumn;
   TextCol->MappingName = "custName";
   TextCol->HeaderText = "Customer Name";
   TextCol->Width = 250;
   ts1->GridColumnStyles->Add( TextCol );
   
   // Create the second table style with columns.
   DataGridTableStyle^ ts2 = gcnew DataGridTableStyle;
   ts2->MappingName = "Orders";
   
   // Set other properties.
   ts2->AlternatingBackColor = Color::LightBlue;
   
   // Create new ColumnStyle objects.
   DataGridColumnStyle^ cOrderDate = gcnew DataGridTextBoxColumn;
   cOrderDate->MappingName = "OrderDate";
   cOrderDate->HeaderText = "Order Date";
   cOrderDate->Width = 100;
   ts2->GridColumnStyles->Add( cOrderDate );
   
   /*Use a PropertyDescriptor to create a formatted
     column. First get the PropertyDescriptorCollection
     for the data source and data member. */
   System::ComponentModel::PropertyDescriptorCollection^ pcol = this->
       BindingContext[myDataSet, "Customers::custToOrders"]->
       GetItemProperties();
   
   /* Create a formatted column using a PropertyDescriptor.
     The formatting character S"c" specifies a currency format. */
   DataGridColumnStyle^ csOrderAmount =
      gcnew DataGridTextBoxColumn( pcol[ "OrderAmount" ],"c",true );
   csOrderAmount->MappingName = "OrderAmount";
   csOrderAmount->HeaderText = "Total";
   csOrderAmount->Width = 100;
   ts2->GridColumnStyles->Add( csOrderAmount );
   
   /* Add the DataGridTableStyle instances to
     the GridTableStylesCollection. */
   myDataGrid->TableStyles->Add( ts1 );
   myDataGrid->TableStyles->Add( ts2 );
}
private void AddCustomDataTableStyle(){
   DataGridTableStyle ts1 = new DataGridTableStyle();
   ts1.MappingName = "Customers";
   // Set other properties.
   ts1.AlternatingBackColor = Color.LightGray;

   /* Add a GridColumnStyle and set its MappingName 
   to the name of a DataColumn in the DataTable. 
   Set the HeaderText and Width properties. */
   
   DataGridColumnStyle boolCol = new DataGridBoolColumn();
   boolCol.MappingName = "Current";
   boolCol.HeaderText = "IsCurrent Customer";
   boolCol.Width = 150;
   ts1.GridColumnStyles.Add(boolCol);
   
   // Add a second column style.
   DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
   TextCol.MappingName = "custName";
   TextCol.HeaderText = "Customer Name";
   TextCol.Width = 250;
   ts1.GridColumnStyles.Add(TextCol);

   // Create the second table style with columns.
   DataGridTableStyle ts2 = new DataGridTableStyle();
   ts2.MappingName = "Orders";

   // Set other properties.
   ts2.AlternatingBackColor = Color.LightBlue;
   
   // Create new ColumnStyle objects.
   DataGridColumnStyle cOrderDate = 
   new DataGridTextBoxColumn();
   cOrderDate.MappingName = "OrderDate";
   cOrderDate.HeaderText = "Order Date";
   cOrderDate.Width = 100;
   ts2.GridColumnStyles.Add(cOrderDate);

   /*Use a PropertyDescriptor to create a formatted
   column. First get the PropertyDescriptorCollection
   for the data source and data member. */
   System.ComponentModel.PropertyDescriptorCollection pcol = 
      this.BindingContext[myDataSet, "Customers.custToOrders"]
      .GetItemProperties();
 
   /* Create a formatted column using a PropertyDescriptor.
   The formatting character "c" specifies a currency format. */     
   DataGridColumnStyle csOrderAmount = 
   new DataGridTextBoxColumn(pcol["OrderAmount"], "c", true);
   csOrderAmount.MappingName = "OrderAmount";
   csOrderAmount.HeaderText = "Total";
   csOrderAmount.Width = 100;
   ts2.GridColumnStyles.Add(csOrderAmount);

   /* Add the DataGridTableStyle instances to 
   the GridTableStylesCollection. */
   myDataGrid.TableStyles.Add(ts1);
   myDataGrid.TableStyles.Add(ts2);
}
Private Sub AddCustomDataTableStyle()
   Dim ts1 As New DataGridTableStyle()
   ts1.MappingName = "Customers"
   ' Set other properties.
   ts1.AlternatingBackColor = Color.LightGray
   ' Add a GridColumnStyle and set its MappingName 
   ' to the name of a DataColumn in the DataTable. 
   ' Set the HeaderText and Width properties. 
     
   Dim boolCol As New DataGridBoolColumn()
   boolCol.MappingName = "Current"
   boolCol.HeaderText = "IsCurrent Customer"
   boolCol.Width = 150
   ts1.GridColumnStyles.Add(boolCol)
     
   ' Add a second column style.
   Dim TextCol As New DataGridTextBoxColumn()
   TextCol.MappingName = "custName"
   TextCol.HeaderText = "Customer Name"
   TextCol.Width = 250
   ts1.GridColumnStyles.Add(TextCol)
     
   ' Create the second table style with columns.
   Dim ts2 As New DataGridTableStyle()
   ts2.MappingName = "Orders"
     
   ' Set other properties.
   ts2.AlternatingBackColor = Color.LightBlue
     
   ' Create new ColumnStyle objects.
   Dim cOrderDate As New DataGridTextBoxColumn()
   cOrderDate.MappingName = "OrderDate"
   cOrderDate.HeaderText = "Order Date"
   cOrderDate.Width = 100
   ts2.GridColumnStyles.Add(cOrderDate)

   ' Use a PropertyDescriptor to create a formatted
   ' column. First get the PropertyDescriptorCollection
   ' for the data source and data member. 
   Dim pcol As System.ComponentModel.PropertyDescriptorCollection = _
   Me.BindingContext(myDataSet, "Customers.custToOrders"). _
   GetItemProperties()

   ' Create a formatted column using a PropertyDescriptor.
   ' The formatting character "c" specifies a currency format. */     
     
   Dim csOrderAmount As _
   New DataGridTextBoxColumn(pcol("OrderAmount"), "c", True)
   csOrderAmount.MappingName = "OrderAmount"
   csOrderAmount.HeaderText = "Total"
   csOrderAmount.Width = 100
   ts2.GridColumnStyles.Add(csOrderAmount)
     
   ' Add the DataGridTableStyle instances to 
   ' the GridTableStylesCollection. 
   myDataGrid.TableStyles.Add(ts1)
   myDataGrid.TableStyles.Add(ts2)
End Sub

Comentários

O GridTableStylesCollection DataGrid contém DataGridTableStyle objetos que permitem que o controle exiba um estilo de grade personalizado para DataTable cada um DataSetem um.The GridTableStylesCollection contains DataGridTableStyle objects that allows the DataGrid control to display a customized grid style for each DataTable in a DataSet.

No controle, a TableStyles propriedade retorna o GridTableStylesCollection. DataGridOn the DataGrid control, the TableStyles property returns the GridTableStylesCollection.

Por padrão, o GridTableStylesCollection não contém nenhum DataGridTableStyle objeto.By default, the GridTableStylesCollection does not contain any DataGridTableStyle objects. Em vez disso DataGrid , o exibe cada tabela usando as configurações padrão para cor, largura e formatação.Instead, the DataGrid displays each table using default settings for color, width, and formatting. Todas as colunas de cada tabela são exibidas.All columns of each table are displayed. Quando um DataGridTableStyle é adicionado à coleção, o DataGrid usa o MappingName para determinar qual objeto fornece os dados para a grade.When a DataGridTableStyle is added to the collection, the DataGrid uses the MappingName to determine which object supplies the data for the grid. Por exemplo, se a fonte de dados for DataSet um que contenha três DataTable objetos MappingName TableName , o deverá corresponder ao de um dos objetos.For example, if the data source is a DataSet that contains three DataTable objects, the MappingName must match the TableName of one of the objects. Se o MappingName não corresponder a nenhum TableName dos valores, as configurações padrão serão usadas para exibir dados de cada tabela e as DataGridTableStyle configurações serão ignoradas.If the MappingName does not match any of the TableName values, the default settings will be used to display data for each table, and the DataGridTableStyle settings will be ignored.

Cuidado

Sempre crie DataGridColumnStyle objetos e adicione-os GridColumnStylesCollection ao GridTableStylesCollectionantes de DataGridTableStyle adicionar objetos ao.Always create DataGridColumnStyle objects and add them to the GridColumnStylesCollection before adding DataGridTableStyle objects to the GridTableStylesCollection. Quando você adiciona um vazio DataGridTableStyle com um valor MappingName válido à coleção, DataGridColumnStyle os objetos são gerados automaticamente para você.When you add an empty DataGridTableStyle with a valid MappingName value to the collection, DataGridColumnStyle objects are automatically generated for you. Consequentemente, uma exceção será gerada se você tentar adicionar novos DataGridColumnStyle objetos com valores duplicados MappingName ao GridColumnStylesCollection.Consequently, an exception will be thrown if you try to add new DataGridColumnStyle objects with duplicate MappingName values to the GridColumnStylesCollection. Como alternativa, desmarque GridColumnStylesCollection o uso Clear do método.Alternatively, clear the GridColumnStylesCollection using the Clear method.

Propriedades

Count Count Count Count

Obtém o número total de elementos na coleção.Gets the total number of elements in the collection.

(Inherited from BaseCollection)
IsReadOnly IsReadOnly IsReadOnly IsReadOnly

Obtém um valor que indica se a coleção é somente leitura.Gets a value indicating whether the collection is read-only.

(Inherited from BaseCollection)
IsSynchronized IsSynchronized IsSynchronized IsSynchronized

Obtém um valor que indica se o acesso à ICollection é sincronizado.Gets a value indicating whether access to the ICollection is synchronized.

(Inherited from BaseCollection)
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Obtém o DataGridTableStyle especificado pelo índice.Gets the DataGridTableStyle specified by index.

Item[String] Item[String] Item[String] Item[String]

Obtém o DataGridTableStyle com o nome especificado.Gets the DataGridTableStyle with the specified name.

List List List List

Obtém a lista subjacente.Gets the underlying list.

SyncRoot SyncRoot SyncRoot SyncRoot

Obtém um objeto que pode ser usado para sincronizar o acesso ao BaseCollection.Gets an object that can be used to synchronize access to the BaseCollection.

(Inherited from BaseCollection)

Métodos

Add(DataGridTableStyle) Add(DataGridTableStyle) Add(DataGridTableStyle) Add(DataGridTableStyle)

Adiciona um DataGridTableStyle a esta coleção.Adds a DataGridTableStyle to this collection.

AddRange(DataGridTableStyle[]) AddRange(DataGridTableStyle[]) AddRange(DataGridTableStyle[]) AddRange(DataGridTableStyle[])

Adiciona uma matriz de estilos de tabela à coleção.Adds an array of table styles to the collection.

Clear() Clear() Clear() Clear()

Limpa a coleção.Clears the collection.

Contains(DataGridTableStyle) Contains(DataGridTableStyle) Contains(DataGridTableStyle) Contains(DataGridTableStyle)

Obtém um valor que indica se a GridTableStylesCollection contém o DataGridTableStyle especificado.Gets a value indicating whether the GridTableStylesCollection contains the specified DataGridTableStyle.

Contains(String) Contains(String) Contains(String) Contains(String)

Obtém um valor que indica se a GridTableStylesCollection contém o DataGridTableStyle especificado pelo nome.Gets a value indicating whether the GridTableStylesCollection contains the DataGridTableStyle specified by name.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

Copia todos os elementos do Array unidimensional atual para o Array unidimensional especificado, começando no índice Array de destino especificado.Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index.

(Inherited from BaseCollection)
CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Cria um objeto que contém todas as informações relevantes necessárias para gerar um proxy usado para se comunicar com um objeto remoto.Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Obtém o objeto que permite a iteração através dos membros da coleção.Gets the object that enables iterating through the members of the collection.

(Inherited from BaseCollection)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Recupera o objeto de serviço de tempo de vida atual que controla a política de ciclo de vida para esta instância.Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Obtém um objeto de serviço de tempo de vida para controlar a política de tempo de vida para essa instância.Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Cria uma cópia superficial do objeto MarshalByRefObject atual.Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs) OnCollectionChanged(CollectionChangeEventArgs) OnCollectionChanged(CollectionChangeEventArgs) OnCollectionChanged(CollectionChangeEventArgs)

Aciona o evento CollectionChanged.Raises the CollectionChanged event.

Remove(DataGridTableStyle) Remove(DataGridTableStyle) Remove(DataGridTableStyle) Remove(DataGridTableStyle)

Remove o DataGridTableStyle especificado.Removes the specified DataGridTableStyle.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Remove um DataGridTableStyle no índice especificado.Removes a DataGridTableStyle at the specified index.

ToString() ToString() ToString() ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Inherited from Object)

Eventos

CollectionChanged CollectionChanged CollectionChanged CollectionChanged

Ocorre quando a coleção foi alterada.Occurs when the collection has changed.

Implantações explícitas de interface

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

Copia a coleção para um Array unidimensional compatível, começando no índice especificado da matriz de destino.Copies the collection to a compatible one-dimensional Array, starting at the specified index of the target array.

ICollection.Count ICollection.Count ICollection.Count ICollection.Count

Obtém o número de itens na coleção.Gets the number of items in the collection.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

Obtém um valor que indica se o acesso à GridTableStylesCollection é sincronizado (thread-safe).Gets a value indicating whether access to the GridTableStylesCollection is synchronized (thread safe).

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

Obtém um objeto que pode ser usado para sincronizar o acesso à coleção.Gets an object that can be used to synchronize access to the collection.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

Retorna um enumerador para a coleção.Returns an enumerator for the collection.

IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

Adiciona um DataGridTableStyle a esta coleção.Adds a DataGridTableStyle to this collection.

IList.Clear() IList.Clear() IList.Clear() IList.Clear()

Limpa a coleção.Clears the collection.

IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

Determina se um elemento está na coleção.Determines whether an element is in the collection.

IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

Retorna o índice baseado em zero da primeira ocorrência do objeto especificado na coleção.Returns the zero-based index of the first occurrence of the specified object in the collection.

IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)

Implementa o método Insert(Int32, Object).Implements the Insert(Int32, Object) method. Sempre gera NotSupportedException.Always throws NotSupportedException.

IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

Obtém um valor que indica se a coleção tem um tamanho fixo.Gets a value indicating whether the collection has a fixed size.

IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly

Obtém um valor que indica se a coleção é somente leitura.Gets a value indicating whether the collection is read-only.

IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

Obtém ou define o elemento no índice especificado.Gets or sets the element at the specified index.

IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

Remove o DataGridTableStyle especificado.Removes the specified DataGridTableStyle.

IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32)

Remove o DataGridColumnStyle com o índice especificado da coleção.Removes the DataGridColumnStyle with the specified index from the collection.

Métodos de Extensão

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Converte os elementos de um IEnumerable para o tipo especificado.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filtra os elementos de um IEnumerable com base em um tipo especificado.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Habilita a paralelização de uma consulta.Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Converte um IEnumerable em um IQueryable.Converts an IEnumerable to an IQueryable.

Aplica-se a

Veja também