Breyta

Deila með


GridColumnStylesCollection Class

Definition

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
[<System.ComponentModel.ListBindable(false)>]
type GridColumnStylesCollection = class
    inherit BaseCollection
    interface IList
    interface ICollection
    interface IEnumerable
Public Class GridColumnStylesCollection
Inherits BaseCollection
Implements IList
Inheritance
GridColumnStylesCollection
Attributes
Implements

Examples

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

On the DataGridTableStyle, you access the GridColumnStylesCollection through the GridColumnStyles property.

The GridColumnStylesCollection uses standard Add and Remove methods to manipulate the collection.

Use the Contains method to determine if a specific property value exists in the collection. Additionally, use the IndexOf method to determine the index of any DataGridColumnStyle object within the collection.

Caution

Always create DataGridColumnStyle objects and add them to the GridColumnStylesCollection before adding DataGridTableStyle objects to the GridTableStylesCollection. When you add an empty DataGridTableStyle with a valid MappingName value to the collection, DataGridColumnStyle objects are automatically generated for you. 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

Gets a value indicating whether access to the ICollection is synchronized.

(Inherited from BaseCollection)
Item[Int32]

Gets the DataGridColumnStyle at a specified index.

Item[PropertyDescriptor]

Gets the DataGridColumnStyle associated with the specified PropertyDescriptor.

Item[String]

Gets the DataGridColumnStyle with the specified name.

List

Gets the list of items in the collection.

SyncRoot

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()

Clears the collection of DataGridColumnStyle objects.

Contains(DataGridColumnStyle)

Gets a value indicating whether the GridColumnStylesCollection contains the specified DataGridColumnStyle.

Contains(PropertyDescriptor)

Gets a value indicating whether the GridColumnStylesCollection contains a DataGridColumnStyle associated with the specified PropertyDescriptor.

Contains(String)

Gets a value indicating whether the GridColumnStylesCollection contains the DataGridColumnStyle with the specified name.

CopyTo(Array, Int32)

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()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(DataGridColumnStyle)

Gets the index of a specified DataGridColumnStyle.

InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

Raises the CollectionChanged event.

Remove(DataGridColumnStyle)

Removes the specified DataGridColumnStyle from the GridColumnStylesCollection.

RemoveAt(Int32)

Removes the DataGridColumnStyle with the specified index from the GridColumnStylesCollection.

ResetPropertyDescriptors()

Sets 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

Occurs when a change is made to the GridColumnStylesCollection.

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

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

Gets a value indicating whether access to the GridColumnStylesCollection is synchronized (thread safe).

ICollection.SyncRoot

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()

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)

Removes the specified DataGridColumnStyle from the GridColumnStylesCollection.

IList.RemoveAt(Int32)

Removes the DataGridColumnStyle at the specified index from the GridColumnStylesCollection.

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

See also