Represents a collection of DataGridColumnStyle objects in the System.Windows.Forms..::.DataGrid control.
<ListBindableAttribute(False)> _ Public Class GridColumnStylesCollection _ Inherits BaseCollection _ Implements IList, ICollection, IEnumerable
[ListBindableAttribute(false)] public class GridColumnStylesCollection : BaseCollection, IList, ICollection, IEnumerable
[ListBindableAttribute(false)] public ref class GridColumnStylesCollection : public BaseCollection, IList, ICollection, IEnumerable
[<ListBindableAttribute(false)>] type GridColumnStylesCollection = class inherit BaseCollection interface IList interface ICollection interface IEnumerable end
The GridColumnStylesCollection type exposes the following members.
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.
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.
The following code example prints information about each DataGridColumnStyle in a GridColumnStylesCollection.
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
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); } } }
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 ); } } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2