GridTableStylesCollection 類別

定義

代表 DataGrid 控制項中 DataGridTableStyle 物件的集合。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
繼承
GridTableStylesCollection
屬性
實作

範例

DataGridTableStyle GridTableStylesCollection下列程式TableStyles代碼範例會建立兩個物件,並將其新增至控制項的屬性所傳回的。DataGridThe 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

備註

GridTableStylesCollection包含DataGrid 物件,DataTable可讓控制項針對中DataSet的每個顯示自訂格線樣式。 DataGridTableStyleThe GridTableStylesCollection contains DataGridTableStyle objects that allows the DataGrid control to display a customized grid style for each DataTable in a DataSet.

在控制項上TableStyles ,屬性GridTableStylesCollection會傳回。 DataGridOn the DataGrid control, the TableStyles property returns the GridTableStylesCollection.

根據預設, GridTableStylesCollection不會包含任何DataGridTableStyle物件。By default, the GridTableStylesCollection does not contain any DataGridTableStyle objects. 相反地, DataGrid會顯示每個資料表使用色彩、寬度和格式的預設設定。Instead, the DataGrid displays each table using default settings for color, width, and formatting. 會顯示每個資料表的所有資料行。All columns of each table are displayed. 將加入至集合時DataGridMappingName 會使用來判斷哪個物件提供方格的資料。DataGridTableStyleWhen a DataGridTableStyle is added to the collection, the DataGrid uses the MappingName to determine which object supplies the data for the grid. 例如, DataSet如果資料來源是包含三個DataTable物件的TableName ,則MappingName必須符合其中一個物件的。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. 如果不符合任何TableName值,則會使用預設設定來顯示每個資料表的資料,而且會忽略這些DataGridTableStyle設定。 MappingNameIf 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.

警告

請一律DataGridColumnStyle GridColumnStylesCollection 先建立DataGridTableStyle物件,並將它們加入至,然後再將物件新增至。 GridTableStylesCollectionAlways 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. 因此,如果您嘗試將具有重複DataGridColumnStyle MappingName值的新物件加入至GridColumnStylesCollection,則會擲回例外狀況。Consequently, an exception will be thrown if you try to add new DataGridColumnStyle objects with duplicate MappingName values to the GridColumnStylesCollection. 或者, GridColumnStylesCollection Clear使用方法來清除。Alternatively, clear the GridColumnStylesCollection using the Clear method.

屬性

Count

取得集合中的項目總數。Gets the total number of elements in the collection.

(繼承來源 BaseCollection)
IsReadOnly

取得值,表示集合是否為唯讀。Gets a value indicating whether the collection is read-only.

(繼承來源 BaseCollection)
IsSynchronized

取得值,表示對 ICollection 的存取是否同步化。Gets a value indicating whether access to the ICollection is synchronized.

(繼承來源 BaseCollection)
Item[Int32]

取得索引所指定的 DataGridTableStyleGets the DataGridTableStyle specified by index.

Item[String]

取得具有指定名稱的 DataGridTableStyleGets the DataGridTableStyle with the specified name.

List

取得基礎清單。Gets the underlying list.

SyncRoot

取得可用以同步存取 BaseCollection 的物件。Gets an object that can be used to synchronize access to the BaseCollection.

(繼承來源 BaseCollection)

方法

Add(DataGridTableStyle)

DataGridTableStyle 新增至這個集合中。Adds a DataGridTableStyle to this collection.

AddRange(DataGridTableStyle[])

將資料表樣式陣列加入集合中。Adds an array of table styles to the collection.

Clear()

清除集合。Clears the collection.

Contains(DataGridTableStyle)

取得值,指出 GridTableStylesCollection 是否含有指定的 DataGridTableStyleGets a value indicating whether the GridTableStylesCollection contains the specified DataGridTableStyle.

Contains(String)

取得值,指出 GridTableStylesCollection 是否含有依名稱指定的 DataGridTableStyleGets a value indicating whether the GridTableStylesCollection contains the DataGridTableStyle specified by name.

CopyTo(Array, Int32)

將目前一維 Array 的所有元素複製到指定的一維 Array (從指定的目的 Array 索引開始)。Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index.

(繼承來源 BaseCollection)
CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetEnumerator()

取得允許逐一查看集合之成員的物件。Gets the object that enables iterating through the members of the collection.

(繼承來源 BaseCollection)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

引發 CollectionChanged 事件。Raises the CollectionChanged event.

Remove(DataGridTableStyle)

移除指定的 DataGridTableStyleRemoves the specified DataGridTableStyle.

RemoveAt(Int32)

移除指定索引處的 DataGridTableStyleRemoves a DataGridTableStyle at the specified index.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

事件

CollectionChanged

發生於集合變更時。Occurs when the collection has changed.

明確介面實作

ICollection.CopyTo(Array, Int32)

將集合複製至相容的一維 Array (從目標陣列的指定索引處開始)。Copies the collection to a compatible one-dimensional Array, starting at the specified index of the target array.

ICollection.Count

取得集合中的項目數目。Gets the number of items in the collection.

ICollection.IsSynchronized

取得值,這個值表示對 GridTableStylesCollection 的存取是否同步 (安全執行緒)。Gets a value indicating whether access to the GridTableStylesCollection is synchronized (thread safe).

ICollection.SyncRoot

取得物件,這個物件可以用來對集合進行同步存取。Gets an object that can be used to synchronize access to the collection.

IEnumerable.GetEnumerator()

傳回集合的列舉程式。Returns an enumerator for the collection.

IList.Add(Object)

DataGridTableStyle 新增至這個集合中。Adds a DataGridTableStyle to this collection.

IList.Clear()

清除集合。Clears the collection.

IList.Contains(Object)

判斷項目是否在集合中。Determines whether an element is in the collection.

IList.IndexOf(Object)

傳回指定的物件在集合中第一個出現的符合項目之索引 (此索引以零為起始)。Returns the zero-based index of the first occurrence of the specified object in the collection.

IList.Insert(Int32, Object)

實作 Insert(Int32, Object) 方法。Implements the Insert(Int32, Object) method. 永遠擲回 NotSupportedExceptionAlways throws NotSupportedException.

IList.IsFixedSize

取得值,這個值表示集合的大小是否是固定的。Gets a value indicating whether the collection has a fixed size.

IList.IsReadOnly

取得值,表示集合是否為唯讀。Gets a value indicating whether the collection is read-only.

IList.Item[Int32]

在指定的索引位置上取得或設定項目。Gets or sets the element at the specified index.

IList.Remove(Object)

移除指定的 DataGridTableStyleRemoves the specified DataGridTableStyle.

IList.RemoveAt(Int32)

將具有指定索引的 DataGridColumnStyle 從集合中移除。Removes the DataGridColumnStyle with the specified index from the collection.

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱