GridColumnStylesCollection 類別

定義

代表 DataGrid 控制項中 DataGridColumnStyle 物件的集合。Represents a collection of DataGridColumnStyle objects in the DataGrid control.

public ref class GridColumnStylesCollection : System::Windows::Forms::BaseCollection, System::Collections::IList
[System.ComponentModel.ListBindable(false)]
public class GridColumnStylesCollection : System.Windows.Forms.BaseCollection, System.Collections.IList
type GridColumnStylesCollection = class
    inherit BaseCollection
    interface IList
    interface ICollection
    interface IEnumerable
Public Class GridColumnStylesCollection
Inherits BaseCollection
Implements IList
繼承
GridColumnStylesCollection
屬性
實作

範例

下列程式碼範例會DataGridColumnStyle GridColumnStylesCollection在中列印每個的相關資訊。The following code example prints information about each DataGridColumnStyle in a GridColumnStylesCollection.

void PrintColumnInformation( DataGrid^ grid )
{
   Console::WriteLine( "Count: {0}", grid->TableStyles->Count );
   GridColumnStylesCollection^ myColumns;
   DataGridTableStyle^ myTableStyle;
   for ( __int32 i = 0; i < grid->TableStyles->Count; i++ )
   {
      myTableStyle = grid->TableStyles[ i ];
      myColumns = myTableStyle->GridColumnStyles;
      
      /* Iterate through the collection and print each 
               object's type and width. */
      DataGridColumnStyle^ dgCol;
      for ( __int32 j = 0; j < myColumns->Count; j++ )
      {
         dgCol = myColumns[ j ];
         Console::WriteLine( dgCol->MappingName );
         Console::WriteLine( dgCol->GetType()->ToString() );
         Console::WriteLine( dgCol->Width );

      }

   }
}

private void PrintColumnInformation(DataGrid grid){
   Console.WriteLine("Count: " + grid.TableStyles.Count);
   GridColumnStylesCollection myColumns;   
   foreach(DataGridTableStyle myTableStyle in grid.TableStyles){

      myColumns = myTableStyle.GridColumnStyles;

      /* Iterate through the collection and print each 
      object's type and width. */
      foreach (DataGridColumnStyle dgCol in myColumns){
         Console.WriteLine(dgCol.MappingName);
         Console.WriteLine(dgCol.GetType().ToString());
         Console.WriteLine(dgCol.Width);
      }
   }
}
Private Sub PrintColumnInformation(grid as DataGrid)
   Console.WriteLine("Count: " & grid.TableStyles.Count)
   Dim myTableStyle As DataGridTableStyle
   Dim myColumns As GridColumnStylesCollection
   Dim dgCol As DataGridColumnStyle
   For Each myTableStyle in grid.TableStyles
      myColumns = myTableStyle.GridColumnStyles
   
      ' Iterate through the collection and print each 
      ' object's type and width.
      For Each dgCol in myColumns
         Console.WriteLine(dgCol.MappingName)
         Console.WriteLine(dgCol.GetType.ToString())
         Console.WriteLine(dgCol.Width)
      Next
   Next
End Sub

備註

在上GridColumnStylesCollection ,您可以透過GridColumnStyles屬性來存取。 DataGridTableStyleOn the DataGridTableStyle, you access the GridColumnStylesCollection through the GridColumnStyles property.

會使用標準AddRemove方法來操作集合。 GridColumnStylesCollectionThe GridColumnStylesCollection uses standard Add and Remove methods to manipulate the collection.

Contains使用方法來判斷集合中是否有特定的屬性值。Use the Contains method to determine if a specific property value exists in the collection. 此外,請使用IndexOf方法來判斷集合中任何DataGridColumnStyle物件的索引。Additionally, use the IndexOf method to determine the index of any DataGridColumnStyle object within the collection.

警告

請一律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.

屬性

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]

取得指定之索引處的 DataGridColumnStyleGets the DataGridColumnStyle at a specified index.

Item[PropertyDescriptor]

取得與指定的 DataGridColumnStyle 相關聯的 PropertyDescriptorGets the DataGridColumnStyle associated with the specified PropertyDescriptor.

Item[String]

取得具有指定名稱的 DataGridColumnStyleGets the DataGridColumnStyle with the specified name.

List

取得集合中的項目清單。Gets the list of items in the collection.

SyncRoot

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

(繼承來源 BaseCollection)

方法

Add(DataGridColumnStyle)

將資料行樣式加入至集合中。Adds a column style to the collection.

AddRange(DataGridColumnStyle[])

將資料行樣式物件陣列加入集合中。Adds an array of column style objects to the collection.

Clear()

清除 DataGridColumnStyle 物件的集合。Clears the collection of DataGridColumnStyle objects.

Contains(DataGridColumnStyle)

取得值,指出 GridColumnStylesCollection 是否含有指定的 DataGridColumnStyleGets a value indicating whether the GridColumnStylesCollection contains the specified DataGridColumnStyle.

Contains(PropertyDescriptor)

取得值,指出 GridColumnStylesCollection 是否包含與指定 DataGridColumnStyle 相關的 PropertyDescriptorGets a value indicating whether the GridColumnStylesCollection contains a DataGridColumnStyle associated with the specified PropertyDescriptor.

Contains(String)

取得值,指出 GridColumnStylesCollection 是否包含具有指定名稱的 DataGridColumnStyleGets a value indicating whether the GridColumnStylesCollection contains the DataGridColumnStyle with the specified 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)
IndexOf(DataGridColumnStyle)

取得指定 DataGridColumnStyle 的索引。Gets the index of a specified DataGridColumnStyle.

InitializeLifetimeService()

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

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。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(DataGridColumnStyle)

將指定的 DataGridColumnStyleGridColumnStylesCollection 中移除。Removes the specified DataGridColumnStyle from the GridColumnStylesCollection.

RemoveAt(Int32)

將有指定索引的 DataGridColumnStyleGridColumnStylesCollection 中移除。Removes the DataGridColumnStyle with the specified index from the GridColumnStylesCollection.

ResetPropertyDescriptors()

將集合中的每個資料行樣式的 PropertyDescriptor 設定為 nullSets the PropertyDescriptor for each column style in the collection to null.

ToString()

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

(繼承來源 Object)

事件

CollectionChanged

發生於 GridColumnStylesCollection 變更時。Occurs when a change is made to the GridColumnStylesCollection.

明確介面實作

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 elements contained in the collection.

ICollection.IsSynchronized

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

ICollection.SyncRoot

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

IEnumerable.GetEnumerator()

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

IList.Add(Object)

將物件加入至集合。Adds an object to the collection.

IList.Clear()

清除 DataGridColumnStyle 物件的集合。Clears the collection of DataGridColumnStyle objects.

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)

這個控制項不支援這個方法。This method is not supported by this control.

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 the element at the specified index.

IList.Remove(Object)

將指定的 DataGridColumnStyleGridColumnStylesCollection 中移除。Removes the specified DataGridColumnStyle from the GridColumnStylesCollection.

IList.RemoveAt(Int32)

DataGridColumnStyle 移除指定之索引處的 GridColumnStylesCollectionRemoves the DataGridColumnStyle at the specified index from the GridColumnStylesCollection.

擴充方法

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.

適用於

另請參閱