ComponentOne Grid for WPF: Using Grid for WPF > Adding Columns to the Grid

Adding Columns to the Grid

You can easily add columns, even unbound columns, to a C1DataGrid grid control. To add columns to your grid, use the Columns property to specify and modify columns. For example, the following XAML adds the bound ProductName and UnitPrice columns to the C1DataGrid control, as well as an unbound Boolean Organic column:

<Window

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:sys="clr-namespace:System;assembly=mscorlib"

    x:Class="Window1"

    Title="Window1" Height="300" Width="300" xmlns:c1grid="clr-namespace:C1.WPF.C1DataGrid;assembly=C1.WPF.C1DataGrid">

    <Grid>       

       <c1grid:C1DataGrid Name="C1DataGrid1" ItemsSource="{Binding Path=ProductsDataSet.Products, ElementName=Window, Mode=Default}">

             <c1grid:C1DataGrid.Columns>

                    <c1grid:Column Caption="Product Name" PropertyName="ProductName"/>

                    <c1grid:Column Caption="Unit Price" PropertyName="UnitPrice"/>

<c1grid:Column Caption="Organic" ColumnName="Organic" DataType="{x:Type sys:Boolean}"/>

             </c1grid:C1DataGrid.Columns>

       </c1grid:C1DataGrid>

     </Grid>

</Window>

Note: You must add a xmlns:sys="clr-namespace:System;assembly=mscorlib" namespace declaration to the <Window> tag for the Boolean DataType declaration above to work correctly.


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.