GridTableStylesCollection Klasa

Definicja

Reprezentuje kolekcję DataGridTableStyle obiektów w kontrolce DataGrid .

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
[<System.ComponentModel.ListBindable(false)>]
type GridTableStylesCollection = class
    inherit BaseCollection
    interface IList
    interface ICollection
    interface IEnumerable
Public Class GridTableStylesCollection
Inherits BaseCollection
Implements IList
Dziedziczenie
GridTableStylesCollection
Atrybuty
Implementuje

Przykłady

Poniższy przykład kodu tworzy dwa DataGridTableStyle obiekty i dodaje każdy do GridTableStylesCollection obiektu zwróconego przez TableStyles właściwość kontrolki DataGrid .

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

Uwagi

Zawiera GridTableStylesCollection obiekty, które umożliwiają kontrolce DataGrid wyświetlanie dostosowanego stylu siatki dla każdego DataTable elementu w obiekcie DataSet.DataGridTableStyle

W kontrolce DataGridTableStyles właściwość zwraca GridTableStylesCollectionwartość .

Domyślnie obiekt GridTableStylesCollection nie zawiera żadnych DataGridTableStyle obiektów. Zamiast tego w tabeli DataGrid są wyświetlane ustawienia domyślne kolorów, szerokości i formatowania. Zostaną wyświetlone wszystkie kolumny każdej tabeli. Po dodaniu obiektu DataGridTableStyle do kolekcji obiekt używa MappingName elementu , aby określić, DataGrid który obiekt dostarcza dane dla siatki. Jeśli na przykład źródło danych jest obiektem zawierającym DataSet trzy DataTable obiekty, MappingName element musi być zgodny TableName z jednym z obiektów. MappingName Jeśli wartość nie jest zgodna z żadną z TableName wartości, ustawienia domyślne będą używane do wyświetlania danych dla każdej tabeli, a DataGridTableStyle ustawienia zostaną zignorowane.

Przestroga

Zawsze twórz DataGridColumnStyle obiekty i dodawaj je do obiektu GridColumnStylesCollection przed dodaniem DataGridTableStyle obiektów do obiektu GridTableStylesCollection. Po dodaniu pustej DataGridTableStyleMappingName wartości do kolekcji DataGridColumnStyle obiekty są generowane automatycznie. W związku z tym w przypadku próby dodania nowych DataGridColumnStyle obiektów z zduplikowanymi MappingName wartościami do obiektu GridColumnStylesCollectionzostanie zgłoszony wyjątek. Możesz też wyczyścić GridColumnStylesCollection metodę Clear przy użyciu metody .

Właściwości

Count

Pobiera całkowitą liczbę elementów w kolekcji.

(Odziedziczone po BaseCollection)
IsReadOnly

Pobiera wartość wskazującą, czy kolekcja jest przeznaczona tylko do odczytu.

(Odziedziczone po BaseCollection)
IsSynchronized

Pobiera wartość wskazującą, czy dostęp do pliku ICollection jest synchronizowany.

(Odziedziczone po BaseCollection)
Item[Int32]

Pobiera określony DataGridTableStyle przez indeks.

Item[String]

Pobiera element DataGridTableStyle o określonej nazwie.

List

Pobiera podstawową listę.

SyncRoot

Pobiera obiekt, który może służyć do synchronizowania dostępu do obiektu BaseCollection.

(Odziedziczone po BaseCollection)

Metody

Add(DataGridTableStyle)

Dodaje element DataGridTableStyle do tej kolekcji.

AddRange(DataGridTableStyle[])

Dodaje tablicę stylów tabeli do kolekcji.

Clear()

Czyści kolekcję.

Contains(DataGridTableStyle)

Pobiera wartość wskazującą, czy GridTableStylesCollection element zawiera określony DataGridTableStyleelement .

Contains(String)

Pobiera wartość wskazującą, czy GridTableStylesCollection element zawiera DataGridTableStyle określony przez nazwę.

CopyTo(Array, Int32)

Kopiuje wszystkie elementy bieżącego jednowymiarowego do określonego jednowymiarowego ArrayArray indeksu rozpoczynającego się od określonego indeksu docelowego Array .

(Odziedziczone po BaseCollection)
CreateObjRef(Type)

Tworzy obiekt zawierający wszystkie istotne informacje wymagane do wygenerowania serwera proxy używanego do komunikowania się z obiektem zdalnym.

(Odziedziczone po MarshalByRefObject)
Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetEnumerator()

Pobiera obiekt, który umożliwia iterowanie za pośrednictwem elementów członkowskich kolekcji.

(Odziedziczone po BaseCollection)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetLifetimeService()
Przestarzałe.

Pobiera bieżący obiekt usługi okresu istnienia, który kontroluje zasady okresu istnienia dla tego wystąpienia.

(Odziedziczone po MarshalByRefObject)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
InitializeLifetimeService()
Przestarzałe.

Uzyskuje obiekt usługi okresu istnienia w celu kontrolowania zasad okresu istnienia dla tego wystąpienia.

(Odziedziczone po MarshalByRefObject)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
MemberwiseClone(Boolean)

Tworzy płytkią kopię bieżącego MarshalByRefObject obiektu.

(Odziedziczone po MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

CollectionChanged Zgłasza zdarzenie.

Remove(DataGridTableStyle)

Usuwa określony DataGridTableStyleelement .

RemoveAt(Int32)

Usuwa obiekt DataGridTableStyle w określonym indeksie.

ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Zdarzenia

CollectionChanged

Występuje, gdy kolekcja uległa zmianie.

Jawne implementacje interfejsu

ICollection.CopyTo(Array, Int32)

Kopiuje kolekcję do zgodnej jednowymiarowej Array, zaczynając od określonego indeksu tablicy docelowej.

ICollection.Count

Pobiera liczbę elementów w kolekcji.

ICollection.IsSynchronized

Pobiera wartość wskazującą, czy dostęp do elementu GridTableStylesCollection jest synchronizowany (bezpieczny wątk).

ICollection.SyncRoot

Pobiera obiekt, który może służyć do synchronizowania dostępu do kolekcji.

IEnumerable.GetEnumerator()

Zwraca moduł wyliczający dla kolekcji.

IList.Add(Object)

Dodaje element DataGridTableStyle do tej kolekcji.

IList.Clear()

Czyści kolekcję.

IList.Contains(Object)

Określa, czy element znajduje się w kolekcji.

IList.IndexOf(Object)

Zwraca indeks zerowy pierwszego wystąpienia określonego obiektu w kolekcji.

IList.Insert(Int32, Object)

Implementuje metodę Insert(Int32, Object) . Zawsze zgłasza wartość NotSupportedException.

IList.IsFixedSize

Pobiera wartość wskazującą, czy kolekcja ma stały rozmiar.

IList.IsReadOnly

Pobiera wartość wskazującą, czy kolekcja jest przeznaczona tylko do odczytu.

IList.Item[Int32]

Pobiera lub ustawia element pod określonym indeksem.

IList.Remove(Object)

Usuwa określony DataGridTableStyleelement .

IList.RemoveAt(Int32)

Usuwa element DataGridColumnStyle z określonym indeksem z kolekcji.

Metody rozszerzania

Cast<TResult>(IEnumerable)

Rzutuje elementy obiektu IEnumerable na określony typ.

OfType<TResult>(IEnumerable)

Filtruje elementy IEnumerable elementu na podstawie określonego typu.

AsParallel(IEnumerable)

Umożliwia równoległość zapytania.

AsQueryable(IEnumerable)

Konwertuje element IEnumerable na .IQueryable

Dotyczy

Zobacz też