GridColumnStylesCollection Class
Assembly: System.Windows.Forms (in system.windows.forms.dll)
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. |
The following code example prints information about each DataGridColumnStyle in a GridColumnStylesCollection.
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 void PrintColumnInformation(DataGrid grid)
{
Console.WriteLine(("Count: " + grid.get_TableStyles().get_Count()));
GridColumnStylesCollection myColumns;
for (int iCtr = 0; iCtr < grid.get_TableStyles().get_Count();
iCtr++) {
DataGridTableStyle myTableStyle =
grid.get_TableStyles().get_Item(iCtr);
myColumns = myTableStyle.get_GridColumnStyles();
/* Iterate through the collection and print each
* object's type and width.
*/
for (int iCtr1 = 0; iCtr1 < myColumns.get_Count(); iCtr1++) {
DataGridColumnStyle dgCol = myColumns.get_Item(iCtr1);
Console.WriteLine(dgCol.get_MappingName());
Console.WriteLine(dgCol.GetType().ToString());
Console.WriteLine(dgCol.get_Width());
}
}
} //PrintColumnInformation
function PrintColumnInformation(grid: DataGrid){ Console.WriteLine("Count: " + grid.TableStyles.Count); var myColumns: GridColumnStylesCollection; for(var myTableStyle in grid.TableStyles){ myColumns = myTableStyle.GridColumnStyles; // Iterate through the collection and print each // object's type and width. for (var dgCol in myColumns){ Console.WriteLine(dgCol.MappingName); Console.WriteLine(dgCol.GetType().ToString()); Console.WriteLine(dgCol.Width); } } }
System.MarshalByRefObject
System.Windows.Forms.BaseCollection
System.Windows.Forms.GridColumnStylesCollection
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Caution: