Xceed DataGrid for WPF v7.2 Documentation
InsertionRow Class
Members  Example 


Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace : InsertionRow Class
Specialization of the Row class, which allows new data items to be added to a grid.
Syntax
'Declaration
 
<TemplatePartAttribute(Name="PART_CellsHost", Type=System.Windows.Controls.Panel)>

<ContentPropertyAttribute("Cells")>

<StyleTypedPropertyAttribute(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)>

<XmlLangPropertyAttribute("Language")>

<UsableDuringInitializationAttribute(True)>

<RuntimeNamePropertyAttribute("Name")>

<UidPropertyAttribute("Uid")>

<TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider)>

<NameScopePropertyAttribute("NameScope", System.Windows.NameScope)>

Public Class InsertionRow 

   Inherits DataRow
'Usage
 
Dim instance As InsertionRow
[TemplatePart(Name="PART_CellsHost", Type=System.Windows.Controls.Panel)]

[ContentProperty("Cells")]

[StyleTypedProperty(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)]

[XmlLangProperty("Language")]

[UsableDuringInitialization(true)]

[RuntimeNameProperty("Name")]

[UidProperty("Uid")]

[TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]

[NameScopeProperty("NameScope", System.Windows.NameScope)]

public class InsertionRow : DataRow 
Remarks

Because rows are virtualized, meaning that they only exist when they are in a grid's viewport, references to them, or one of their cells, should not be kept.

Insertion and modification (read/write) of the data items contained in a grid will only function if TwoWay binding mode is used. For more information, refer to the Binding.Mode property topic in the Microsoft Windows SDK.

Fixed Columns vs. Templates  

In order to support fixed columns when creating a new row template for a table-view layout, the following criteria must be met:

  1. The PART_CellsHost template part must be a FixedCellPanel.
  2. The FixedCellCount property of the FixedCellPanel must be bound to the table view's FixedColumnCount property using a TwoWay ViewBinding.

The fixed-cell-panel properties listed below are also usually bound when provided a new row template for a table-view layout:

  1. SplitterStyle (TemplateBinding xcdg:TableView.FixedColumnSplitterStyle)
  2. SplitterWidth (xcdg:ViewBinding FixedColumnSplitterWidth)
  3. ShowSplitter (xcdg:ViewBinding ShowFixedColumnSplitter)
  4. FixedColumnDropMarkPen (xcdg:ViewBinding FixedColumnDropMarkPen)

If a new template is provided for a DataGridControl and fixed columns are to be supported, it is essential that a TableViewScrollViewer be used. This scroll viewer is responsible for preserving the TranslateTransforms that fix and scroll elements, as well as executing the PageLeft and PageRight actions according to the reduced viewport.  It is also recommended that an AdornerDecorator be located above the TableViewScrollViewer of the templated DataGridControl to support drag and dropping of the fixed-column splitter correctly.

The mode of an insertion row can be set by using the InsertionMode property.

Example
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>
Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Media.Visual
            System.Windows.UIElement
               System.Windows.FrameworkElement
                  System.Windows.Controls.Control
                     Xceed.Wpf.DataGrid.Row
                        Xceed.Wpf.DataGrid.DataRow
                           Xceed.Wpf.DataGrid.InsertionRow

Requirements

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

See Also

Reference

InsertionRow Members
Xceed.Wpf.DataGrid Namespace

DataGrid Fundamentals

Providing Data