GridColumnStylesCollection Class

Definition

表示 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
Inheritance
GridColumnStylesCollection
Attributes
Implements

Examples

下面的代码示例在 GridColumnStylesCollection中打印有关每个 DataGridColumnStyle 的信息。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

Remarks

DataGridTableStyle上,通过 GridColumnStyles 属性访问 GridColumnStylesCollectionOn the DataGridTableStyle, you access the GridColumnStylesCollection through the GridColumnStyles property.

GridColumnStylesCollection 使用标准 AddRemove 方法对集合进行操作。The 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.

Caution

在将 DataGridTableStyle 对象添加到 GridTableStylesCollection之前,始终创建 DataGridColumnStyle 对象并将其添加到 GridColumnStylesCollection 中。Always create DataGridColumnStyle objects and add them to the GridColumnStylesCollection before adding DataGridTableStyle objects to the GridTableStylesCollection. 将具有有效 MappingName 值的空 DataGridTableStyle 添加到集合时,会自动为你生成 DataGridColumnStyle 对象。When you add an empty DataGridTableStyle with a valid MappingName value to the collection, DataGridColumnStyle objects are automatically generated for you. 因此,如果尝试将具有重复 MappingName 值的新 DataGridColumnStyle 对象添加到 GridColumnStylesCollection,则会引发异常。Consequently, an exception will be thrown if you try to add new DataGridColumnStyle objects with duplicate MappingName values to the GridColumnStylesCollection.

Properties

Count

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

(Inherited from BaseCollection)
IsReadOnly

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

(Inherited from BaseCollection)
IsSynchronized

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

(Inherited from 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.

(Inherited from BaseCollection)

Methods

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.

(Inherited from BaseCollection)
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)

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

(Inherited from Object)
GetEnumerator()

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

(Inherited from BaseCollection)
GetHashCode()

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

(Inherited from Object)
GetLifetimeService()

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

(Inherited from MarshalByRefObject)
GetType()

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

(Inherited from 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.

(Inherited from MarshalByRefObject)
MemberwiseClone()

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

(Inherited from Object)
MemberwiseClone(Boolean)

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

(Inherited from MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

引发 CollectionChanged 事件。Raises the CollectionChanged event.

Remove(DataGridColumnStyle)

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

RemoveAt(Int32)

DataGridColumnStyle 中移除具有指定索引的 GridColumnStylesCollectionRemoves 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.

(Inherited from Object)

Events

CollectionChanged

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

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

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

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

IList.RemoveAt(Int32)

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

Extension Methods

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.

Applies to

See also