Specialization of the
Row class, which allows new data items to be added to a grid.
All examples in this topic assume that the grid is bound to the
Orders table of the Northwind database, unless stated otherwise.
The following example demonstrates how to provide, through a style, a new InsertionRow template. In order to preserve the fixed-column splitter in the insertion row, we need to use a FixedCellPanel as the PART_CellsHost template part.The following example demonstrates how to initialize the values of the ShipCountry, ShipCity, and ShipVia columns in an insertion row located in the fixed headers. The handler for the InitializingInsertionRow event is defined in the code-behind class.
The columns that are contained in the grid will be limited to those specified in the ItemProperties of the DataGridCollectionViewSource.The following example demonstrates how to retrieve a reference to an InsertionRow that is located in the fixed headers of a grid by handling its Loaded event.
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
<Grid.Resources>
<xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
Source="{Binding Source={x:Static Application.Current},
Path=Orders}"
AutoCreateItemProperties="False"/>
<Style x:Key="insertionrow_style"
TargetType="{x:Type xcdg:InsertionRow}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type xcdg:InsertionRow}">
<Expander Header="Insert New Data">
<Border BorderBrush="LightBlue"
BorderThickness="0, 1, 0, 1">
<xcdg:FixedCellPanel x:Name="PART_CellsHost"
FixedCellCount="{xcdg:ViewBinding FixedColumnCount, Mode=TwoWay}"
SplitterStyle="{TemplateBinding xcdg:TableView.FixedColumnSplitterStyle}"
SplitterWidth="{xcdg:ViewBinding FixedColumnSplitterWidth}"
ShowSplitter="{xcdg:ViewBinding ShowFixedColumnSplitter}"
FixedColumnDropMarkPen="{xcdg:ViewBinding FixedColumnDropMarkPen}"
Background="LightBlue"/>
</Border>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<xcdg:DataGridControl x:Name="OrdersGrid"
ItemsSource="{Binding Source={StaticResource cvs_orders}}">
<xcdg:DataGridControl.View>
<xcdg:TableView>
<xcdg:TableView.FixedFooters>
<DataTemplate>
<xcdg:InsertionRow Style="{StaticResource insertionrow_style}"/>
</DataTemplate>
</xcdg:TableView.FixedFooters>
</xcdg:TableView>
</xcdg:DataGridControl.View>
</xcdg:DataGridControl>
</Grid>
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
<Grid.Resources>
<xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
Source="{Binding Source={x:Static Application.Current},
Path=Orders}"
AutoCreateItemProperties="False">
<xcdg:DataGridCollectionViewSource.ItemProperties>
<xcdg:DataGridItemProperty Name="ShipCountry" Title="Country"/>
<xcdg:DataGridItemProperty Name="ShipCity" Title="City"/>
<xcdg:DataGridItemProperty Name="ShipVia" Title="Ship With"/>
</xcdg:DataGridCollectionViewSource.ItemProperties>
</xcdg:DataGridCollectionViewSource>
</Grid.Resources>
<xcdg:DataGridControl x:Name="OrdersGrid"
ItemsSource="{Binding Source={StaticResource cvs_orders}}"
InitializingInsertionRow="InitInsertion">
<xcdg:DataGridControl.View>
<xcdg:CardView>
<xcdg:CardView.FixedHeaders>
<DataTemplate>
<xcdg:InsertionRow/>
</DataTemplate>
</xcdg:CardView.FixedHeaders>
</xcdg:CardView>
</xcdg:DataGridControl.View>
</xcdg:DataGridControl>
</Grid>
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
<Grid.Resources>
<xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
Source="{Binding Source={x:Static Application.Current},
Path=Orders}"
AutoCreateItemProperties="False/>
</Grid.Resources>
<xcdg:DataGridControl x:Name="OrdersGrid"
ItemsSource="{Binding Source={StaticResource cvs_orders}}">
<xcdg:DataGridControl.View>
<xcdg:TableView>
<xcdg:TableView.FixedHeaders>
<DataTemplate>
<xcdg:InsertionRow Loaded="InsertionRow_Loaded"/>
</DataTemplate>
</xcdg:TableView.FixedHeaders>
</xcdg:TableView>
</xcdg:DataGridControl.View>
</xcdg:DataGridControl>
</Grid>
Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2