Using Type Based Column Styles
In the 2009 v1 release of ComponentOne Grid for WPF, the ability to format columns by type was added. The TypeBasedColumnStyles and DefaultTypeBasedColumnStyles properties allow you to format how columns appear depending on their DataType – for example, you can format columns differently depending on if the data they contain are strings, Boolean values, integers, and so on.
To format columns, by type, add XAML defining TypeBasedColumnStyles to your grid. The following example maps three styles to columns representing the System.String, System.Double, and System.DateTime data types:
<c1grid:C1DataGrid Name="C1DataGrid1" ItemsSource="{Binding Path=ProductsDataSet.Products, ElementName=window, Mode=Default}">
<c1grid:C1DataGrid.TypeBasedColumnStyles>
<Style TargetType="c1grid:Column" x:Key="{x:Type sys:String}">
<Setter Property="HeaderCellWidth" Value="100"/>
<Setter Property="Caption" Value="Description"/>
</Style>
<Style TargetType="c1grid:Column" x:Key="{x:Type sys:Double}">
<Setter Property="HeaderCellWidth" Value="50"/>
<Setter Property="Format" Value="0.00"/>
</Style>
<Style TargetType="c1grid:Column" x:Key="{x:Type sys:DateTime}">
<Setter Property="HeaderCellWidth" Value="70"/>
<Setter Property="Format" Value="d"/>
</Style>
</c1grid:C1DataGrid.TypeBasedColumnStyles>
</c1grid:C1DataGrid>
Note: You must add a xmlns:sys="clr-namespace:System;assembly=mscorlib" namespace declaration to the <Window> tag for the above example to work correctly.
|