Sdílet prostřednictvím


GridTableStylesCollection Třída

Definice

Upozornění

DataGrid is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use DataGridView instead.

Představuje kolekci DataGridTableStyle objektů v ovládacím DataGrid prvku.

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)]
[System.ComponentModel.Browsable(false)]
[System.Obsolete("`DataGrid` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `DataGridView` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
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
[<System.ComponentModel.ListBindable(false)>]
[<System.ComponentModel.Browsable(false)>]
[<System.Obsolete("`DataGrid` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `DataGridView` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
type GridTableStylesCollection = class
    inherit BaseCollection
    interface IList
    interface ICollection
    interface IEnumerable
Public Class GridTableStylesCollection
Inherits BaseCollection
Implements IList
Dědičnost
GridTableStylesCollection
Atributy
Implementuje

Příklady

Následující příklad kódu vytvoří dva DataGridTableStyle objekty a přidá každý do GridTableStylesCollection vrácené TableStyles vlastností DataGrid ovládacího prvku.

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

Poznámky

Obsahuje GridTableStylesCollectionDataGridTableStyle objekty, které umožňují ovládacímu DataGrid prvku zobrazit přizpůsobený styl mřížky pro každý DataTable v objektu DataSet.

V ovládacím DataGrid prvku TableStyles vrátí GridTableStylesCollectionvlastnost .

Ve výchozím nastavení neobsahuje GridTableStylesCollection žádné DataGridTableStyle objekty. DataGrid Místo toho se zobrazí každá tabulka s výchozím nastavením pro barvu, šířku a formátování. Zobrazí se všechny sloupce každé tabulky. DataGridTableStyle Při přidání do kolekce DataGrid se použije k určení objektuMappingName, který poskytuje data pro mřížku. Pokud je DataSet zdrojem dat například tři DataTable objekty, MappingName musí se shodovat TableName s jedním z objektů. MappingName Pokud se žádná z TableName hodnot neshoduje, použije se výchozí nastavení k zobrazení dat pro každou tabulku a DataGridTableStyle nastavení se bude ignorovat.

Upozornění

Vždy vytvořte DataGridColumnStyle objekty a před GridColumnStylesCollection přidáním DataGridTableStyle objektů do objektu GridTableStylesCollection. Když do kolekce přidáte prázdnou DataGridTableStyle hodnotu s platnou MappingName hodnotou, DataGridColumnStyle objekty se automaticky vygenerují za vás. V důsledku toho bude vyvolán výjimka, pokud se pokusíte přidat nové DataGridColumnStyle objekty s duplicitními MappingName hodnotami do GridColumnStylesCollection. Případně vymažte GridColumnStylesCollection metodu Clear .

Vlastnosti

Name Description
Count
Zastaralé.

Získá celkový počet prvků v kolekci.

(Zděděno od BaseCollection)
IsReadOnly
Zastaralé.

Získá hodnotu určující, zda kolekce je jen pro čtení.

(Zděděno od BaseCollection)
IsSynchronized
Zastaralé.

Získá hodnotu označující, zda je přístup k sadě ICollection synchronizován.

(Zděděno od BaseCollection)
Item[Int32]
Zastaralé.

DataGridTableStyle Získá určený indexem.

Item[String]
Zastaralé.

Získá se DataGridTableStyle zadaným názvem.

List
Zastaralé.

Získá podkladový seznam.

List
Zastaralé.

Získá seznam prvků obsažených BaseCollection v instanci.

(Zděděno od BaseCollection)
SyncRoot
Zastaralé.

Získá objekt, který lze použít k synchronizaci přístupu k BaseCollection.

(Zděděno od BaseCollection)

Metody

Name Description
Add(DataGridTableStyle)
Zastaralé.

Přidá do této kolekce.DataGridTableStyle

AddRange(DataGridTableStyle[])
Zastaralé.

Přidá do kolekce pole stylů tabulky.

Clear()
Zastaralé.

Vymaže kolekci.

Contains(DataGridTableStyle)
Zastaralé.

Získá hodnotu určující, zda GridTableStylesCollection obsahuje zadaný DataGridTableStyle.

Contains(String)
Zastaralé.

Získá hodnotu určující, zda GridTableStylesCollection obsahuje zadaný DataGridTableStyle podle názvu.

CopyTo(Array, Int32)
Zastaralé.

Zkopíruje všechny prvky aktuálního jednorozměrného Array do zadaného jednorozměrného Array indexu počínaje zadaným cílovým Array indexem.

(Zděděno od BaseCollection)
CreateObjRef(Type)
Zastaralé.

Vytvoří objekt, který obsahuje všechny relevantní informace potřebné k vygenerování proxy serveru sloužícího ke komunikaci se vzdáleným objektem.

(Zděděno od MarshalByRefObject)
Equals(Object)
Zastaralé.

Určuje, zda je zadaný objekt roven aktuálnímu objektu.

(Zděděno od Object)
GetEnumerator()
Zastaralé.

Získá objekt, který umožňuje iterace prostřednictvím členů kolekce.

(Zděděno od BaseCollection)
GetHashCode()
Zastaralé.

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetLifetimeService()
Zastaralé.

Načte objekt služby aktuální životnosti, který řídí zásady životnosti pro tuto instanci.

(Zděděno od MarshalByRefObject)
GetType()
Zastaralé.

Získá Type aktuální instance.

(Zděděno od Object)
InitializeLifetimeService()
Zastaralé.

Získá objekt služby životnosti pro řízení zásad životnosti pro tuto instanci.

(Zděděno od MarshalByRefObject)
MemberwiseClone()
Zastaralé.

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
MemberwiseClone(Boolean)
Zastaralé.

Vytvoří mělkou kopii aktuálního MarshalByRefObject objektu.

(Zděděno od MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)
Zastaralé.

CollectionChanged Vyvolá událost.

Remove(DataGridTableStyle)
Zastaralé.

Odebere zadanou DataGridTableStylepoložku .

RemoveAt(Int32)
Zastaralé.

Odebere zadanou indexovou DataGridTableStyle položku.

ToString()
Zastaralé.

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Událost

Name Description
CollectionChanged
Zastaralé.

Nastane, když se kolekce změnila.

Explicitní implementace rozhraní

Name Description
ICollection.CopyTo(Array, Int32)
Zastaralé.

Zkopíruje kolekci do kompatibilního jednorozměrného Array, počínaje zadaným indexem cílového pole.

ICollection.Count
Zastaralé.

Získá počet položek v kolekci.

ICollection.IsSynchronized
Zastaralé.

Získá hodnotu označující, zda je přístup k GridTableStylesCollection této synchronizaci (bezpečné vlákno).

ICollection.SyncRoot
Zastaralé.

Získá objekt, který lze použít k synchronizaci přístupu k kolekci.

IEnumerable.GetEnumerator()
Zastaralé.

Vrátí enumerátor pro kolekci.

IList.Add(Object)
Zastaralé.

Přidá do této kolekce.DataGridTableStyle

IList.Clear()
Zastaralé.

Vymaže kolekci.

IList.Contains(Object)
Zastaralé.

Určuje, zda je prvek v kolekci.

IList.IndexOf(Object)
Zastaralé.

Vrátí index založený na nule prvního výskytu zadaného objektu v kolekci.

IList.Insert(Int32, Object)
Zastaralé.

Implementuje metodu Insert(Int32, Object) . Vždy vyvolá NotSupportedException.

IList.IsFixedSize
Zastaralé.

Získá hodnotu určující, zda kolekce má pevnou velikost.

IList.IsReadOnly
Zastaralé.

Získá hodnotu určující, zda kolekce je jen pro čtení.

IList.Item[Int32]
Zastaralé.

Získá nebo nastaví prvek v zadaném indexu.

IList.Remove(Object)
Zastaralé.

Odebere zadanou DataGridTableStylepoložku .

IList.RemoveAt(Int32)
Zastaralé.

Odebere ze DataGridColumnStyle kolekce zadaný index.

Metody rozšíření

Name Description
AsParallel(IEnumerable)
Zastaralé.

Umožňuje paralelizaci dotazu.

AsQueryable(IEnumerable)
Zastaralé.

Převede IEnumerable na IQueryable.

Cast<TResult>(IEnumerable)
Zastaralé.

Přetypuje prvky IEnumerable na zadaný typ.

OfType<TResult>(IEnumerable)
Zastaralé.

Filtruje prvky IEnumerable na základě zadaného typu.

Platí pro

Viz také