GridColumnStylesCollection GridColumnStylesCollection GridColumnStylesCollection GridColumnStylesCollection Class

定义

表示 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
继承
GridColumnStylesCollectionGridColumnStylesCollectionGridColumnStylesCollectionGridColumnStylesCollection
属性
实现

示例

下面的代码示例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

注解

在上DataGridTableStyleGridColumnStylesCollection 通过GridColumnStyles属性访问。On 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然后将对象GridTableStylesCollection添加到中。Always 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 Count Count Count

获取集合中元素的总数。Gets the total number of elements in the collection.

(Inherited from BaseCollection)
IsReadOnly IsReadOnly IsReadOnly IsReadOnly

获取一个值,该值指示集合是否为只读。Gets a value indicating whether the collection is read-only.

(Inherited from BaseCollection)
IsSynchronized IsSynchronized IsSynchronized IsSynchronized

获取一个值,该值指示对 ICollection 的访问是否同步。Gets a value indicating whether access to the ICollection is synchronized.

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

获取指定索引处的 DataGridColumnStyleGets the DataGridColumnStyle at a specified index.

Item[PropertyDescriptor] Item[PropertyDescriptor] Item[PropertyDescriptor] Item[PropertyDescriptor]

获取与指定 DataGridColumnStyle 关联的 PropertyDescriptorGets the DataGridColumnStyle associated with the specified PropertyDescriptor.

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

获取具有指定名称的 DataGridColumnStyleGets the DataGridColumnStyle with the specified name.

List List List List

获取集合中项的列表。Gets the list of items in the collection.

SyncRoot SyncRoot SyncRoot SyncRoot

获取可用于同步对 BaseCollection 的访问的对象。Gets an object that can be used to synchronize access to the BaseCollection.

(Inherited from BaseCollection)

方法

Add(DataGridColumnStyle) Add(DataGridColumnStyle) Add(DataGridColumnStyle) Add(DataGridColumnStyle)

将列样式添加到集合中。Adds a column style to the collection.

AddRange(DataGridColumnStyle[]) AddRange(DataGridColumnStyle[]) AddRange(DataGridColumnStyle[]) AddRange(DataGridColumnStyle[])

将列样式对象数组添加到集合中。Adds an array of column style objects to the collection.

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

清除 DataGridColumnStyle 对象的集合。Clears the collection of DataGridColumnStyle objects.

Contains(DataGridColumnStyle) Contains(DataGridColumnStyle) Contains(DataGridColumnStyle) Contains(DataGridColumnStyle)

获取一个值,该值指示 GridColumnStylesCollection 是否包含指定的 DataGridColumnStyleGets a value indicating whether the GridColumnStylesCollection contains the specified DataGridColumnStyle.

Contains(PropertyDescriptor) Contains(PropertyDescriptor) Contains(PropertyDescriptor) Contains(PropertyDescriptor)

获取一个值,该值指示 GridColumnStylesCollection 是否包含与指定 DataGridColumnStyle 关联的 PropertyDescriptorGets a value indicating whether the GridColumnStylesCollection contains a DataGridColumnStyle associated with the specified PropertyDescriptor.

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

获取一个值,该值指示 GridColumnStylesCollection 是否包含具有指定名称的 DataGridColumnStyleGets a value indicating whether the GridColumnStylesCollection contains the DataGridColumnStyle with the specified name.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) 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.

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

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。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)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

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

获取能够循环访问集合成员的对象。Gets the object that enables iterating through the members of the collection.

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

作为默认哈希函数。Serves as the default hash function.

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

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

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

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IndexOf(DataGridColumnStyle) IndexOf(DataGridColumnStyle) IndexOf(DataGridColumnStyle) IndexOf(DataGridColumnStyle)

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

InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

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

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

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

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

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

引发 CollectionChanged 事件。Raises the CollectionChanged event.

Remove(DataGridColumnStyle) Remove(DataGridColumnStyle) Remove(DataGridColumnStyle) Remove(DataGridColumnStyle)

DataGridColumnStyle 中移除指定的 GridColumnStylesCollectionRemoves the specified DataGridColumnStyle from the GridColumnStylesCollection.

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

DataGridColumnStyle 中移除具有指定索引的 GridColumnStylesCollectionRemoves the DataGridColumnStyle with the specified index from the GridColumnStylesCollection.

ResetPropertyDescriptors() ResetPropertyDescriptors() ResetPropertyDescriptors() ResetPropertyDescriptors()

将集合中每个列样式的 PropertyDescriptor 设置为 nullSets the PropertyDescriptor for each column style in the collection to null.

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

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

事件

CollectionChanged CollectionChanged CollectionChanged CollectionChanged

GridColumnStylesCollection 进行更改后发生。Occurs when a change is made to the GridColumnStylesCollection.

显式界面实现

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

从目标数组的指定索引处开始,将集合复制到兼容的一维 ArrayCopies 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

获取集合中包含的元素数。Gets the number of elements contained in the collection.

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

获取一个值,该值指示是否同步对 GridColumnStylesCollection 的访问(线程安全)。Gets a value indicating whether access to the GridColumnStylesCollection is synchronized (thread safe).

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

获取可用于同步对 GridColumnStylesCollection 的访问的对象。Gets an object that can be used to synchronize access to the GridColumnStylesCollection.

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

返回集合的枚举数。Returns an enumerator for the collection.

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

将对象添加到集合。Adds an object to the collection.

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

清除 DataGridColumnStyle 对象的集合。Clears the collection of DataGridColumnStyle objects.

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

确定某元素是否在集合中。Determines whether an element is in the collection.

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

返回指定对象在集合中的第一个匹配项的从零开始的索引。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)

此控件不支持此方法。This method is not supported by this control.

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

获取一个值,该值指示集合是否具有固定大小。Gets a value indicating whether the collection has a fixed size.

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

获取一个值,该值指示集合是否为只读。Gets a value indicating whether the collection is read-only.

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

获取指定索引处的元素。Gets the element at the specified index.

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

DataGridColumnStyle 中移除指定的 GridColumnStylesCollectionRemoves the specified DataGridColumnStyle from the GridColumnStylesCollection.

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

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

扩展方法

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

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

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

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

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

启用查询的并行化。Enables parallelization of a query.

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

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅