DataRow Class
See Also  Members   Example 
Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace : DataRow Class

Specialization of the Row that represents a row that contains a collection of DataCells. DataRows are the visual representation of the data items that are displayed in a grid's viewport.

Object Model



Syntax

Visual Basic (Declaration) 
Public Class DataRow 
   Inherits Row
   Implements IEditableObjectISupportInitializeIFrameworkInputElementIInputElementIHaveResourcesIAnimatableDUCE.IResource, IDataGridItemContainer, IPrintInfo 
C# 
public class DataRow : Row, IEditableObjectISupportInitializeIFrameworkInputElementIInputElementIHaveResourcesIAnimatableDUCE.IResource, IDataGridItemContainer, IPrintInfo  

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 alternate the appearance of data row styles using the IndexToOddConverter.
XAMLCopy Code
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> 
  <Grid.Resources> 
 
 
    <xcdg:IndexToOddConverter x:Key="rowIndexConverter"/>    
 
    <Style TargetType="{x:Type xcdg:DataRow}"> 
      <Style.Triggers> 
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, 
                                       Path=(xcdg:DataGridVirtualizingPanel.ItemIndex), 
                                       Converter={StaticResource rowIndexConverter}}" 
                               Value="True"> 
          <Setter Property="Background"> 
            <Setter.Value> 
              <SolidColorBrush Color="LightGray" 
                               Opacity="0.1"/> 
            </Setter.Value> 
          </Setter> 
        </DataTrigger> 
      </Style.Triggers> 
    </Style> 
    <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" 
                                   Source="{Binding Source={x:Static Application.Current}, 
                                                    Path=Orders}"/> 
  </Grid.Resources> 
 
  <xcdg:DataGridControl x:Name="OrdersGrid" 
                        ItemsSource="{Binding Source={StaticResource cvs_orders}}"> 
  </xcdg:DataGridControl> 
</Grid>
The following example demonstrates how to changed the background color of a DataRow according to the value of one of its cells using DataTriggers.
XAMLCopy Code
<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}"/> 
   <Style TargetType="{x:Type xcdg:DataRow}"> 
     <Style.Triggers> 
       <DataTrigger Binding="{Binding Path=[EmployeeID]}" Value="1"> 
         <Setter Property="Background" Value="Pink"/> 
       </DataTrigger> 
       <DataTrigger Binding="{Binding Path=[EmployeeID]}" Value="3"> 
         <Setter Property="Background" Value="Blue"/> 
       </DataTrigger> 
     </Style.Triggers> 
   </Style> 
 </Grid.Resources> 
<xcdg:DataGridControl x:Name="OrdersGrid" 
                        ItemsSource="{Binding Source={StaticResource cvs_orders}}"/> 
</Grid>
The following example demonstrates how to subscribe the MouseEnter and MouseLeave events of each DataRow using EventTriggers in an implicit style.
XAMLCopy Code
<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}"/> 
 
    <Style TargetType="{x:Type xcdg:DataRow}"> 
      <EventSetter Event="MouseEnter" 
                   Handler="DataRowMouseEnter"/> 
 
      <EventSetter Event="MouseLeave" 
                   Handler="DataRowMouseLeave"/> 
    </Style> 
  </Grid.Resources> 
      
  <xcdg:DataGridControl x:Name="OrdersGrid" 
                        ItemsSource="{Binding Source={StaticResource cvs_orders}}" 
                        View="TableView.LunaNormalColorTheme"/> 
</Grid>
The following example demonstrates how to display a row's visual index in its corresponding row selector by creating a style targeting the RowSelector type that displays the value of its ItemIndex property as its content. The style is then assigned to the RowSelector.RowSelectorStyle attached property, which is set by the implicit DataRow style.
XAMLCopy Code
<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}" /> 
 
    <Style x:Key="itemIndexSelectorStyle" 
           TargetType="{x:Type xcdg:RowSelector}"> 
      <Setter Property="Content" 
              Value="{Binding RelativeSource={RelativeSource Self}, Path=ItemIndex}"/> 
    </Style> 
    <Style TargetType="{x:Type xcdg:DataRow}"> 
      <Setter Property="xcdg:RowSelector.RowSelectorStyle" 
              Value="{StaticResource itemIndexSelectorStyle}" /> 
    </Style> 
  </Grid.Resources> 
 
  <xcdg:DataGridControl x:Name="OrdersGrid" 
                            ItemsSource="{Binding Source={StaticResource cvs_orders}}" /> 
</Grid>
The following example demonstrates how to provide, through a style, a new ControlTemplate for DataRow objects. The columns that are contained in the grid will be limited to those specified in the ItemProperties of the DataGridCollectionViewSource.
XAMLCopy Code
<Grid> 
 <Grid.Resources> 
   <xcdg:DataGridCollectionViewSource x:Key="cvs_employees" 
                                      Source="{Binding Source={x:Static Application.Current}, 
                                                       Path=Employees}" 
                                      AutoCreateItemProperties="False"> 
     <xcdg:DataGridCollectionViewSource.ItemProperties> 
       <xcdg:DataGridItemProperty Name="LastName"/> 
       <xcdg:DataGridItemProperty Name="FirstName"/> 
       <xcdg:DataGridItemProperty Name="Photo"/> 
       <xcdg:DataGridItemProperty Name="Title"/> 
       <xcdg:DataGridItemProperty Name="Notes"/> 
       <xcdg:DataGridItemProperty Name="EmployeeID"/> 
       <xcdg:DataGridItemProperty Name="TitleOfCourtesy"/> 
       <xcdg:DataGridItemProperty Name="HireDate"/> 
       <xcdg:DataGridItemProperty Name="Extension"/> 
     </xcdg:DataGridCollectionViewSource.ItemProperties> 
   </xcdg:DataGridCollectionViewSource> 
   <ControlTemplate x:Key="titleLessCell" 
                    TargetType="xcdg:DataCell"> 
     <ContentPresenter Content="{xcdg:CellContentBinding}" 
                       ContentTemplate="{TemplateBinding ContentTemplate}" 
                       ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"/> 
   </ControlTemplate> 
   <Style x:Key="customCardViewDataRow" 
          TargetType="{x:Type xcdg:DataRow}"> 
     <Setter Property="Background" 
             Value="Transparent"/> 
     <Setter Property="Template"> 
       <Setter.Value> 
         <ControlTemplate TargetType="{x:Type xcdg:DataRow}"> 
           <Border x:Name="PART_RowFocusRoot" 
                   Background="{TemplateBinding Background}" 
                   BorderBrush="{TemplateBinding BorderBrush}" 
                   BorderThickness="{TemplateBinding BorderThickness}" 
                   Padding="{TemplateBinding Padding}"> 
             <Grid> 
               <StackPanel> 
                 <DockPanel> 
                   <!-- The photo is at the left. --> 
                   <Grid DockPanel.Dock="Left" 
                         Margin="3,4,2,2" 
                         MaxWidth="85" 
                         MaxHeight="85"> 
                     <xcdg:DataCell FieldName="Photo" 
                                     Template="{StaticResource titleLessCell}"/> 
                   </Grid> 
                   <StackPanel Margin="8,0,0,0"> 
                     <StackPanel Orientation="Horizontal"> 
                       <xcdg:DataCell FieldName="TitleOfCourtesy" 
                                      FontSize="16" 
                                      Template="{StaticResource titleLessCell}"/> 
                       <TextBlock Text=" "/> 
                       <xcdg:DataCell FieldName="FirstName" 
                                      FontSize="16" 
                                      Template="{StaticResource titleLessCell}"/> 
                       <TextBlock Text=" "/> 
                       <xcdg:DataCell FieldName="LastName" 
                                      FontSize="16" 
                                      Template="{StaticResource titleLessCell}"/> 
                     </StackPanel> 
                      <xcdg:DataCell FieldName="Title" 
                                    FontSize="14" 
                                    Template="{StaticResource titleLessCell}"/> 
                       <Border BorderThickness="1" 
                               BorderBrush="#999999" 
                               Margin="0,2,0,2"/> 
                         <StackPanel x:Name="PART_CellsHost" 
                                     Orientation="Vertical" 
                                     Grid.IsSharedSizeScope="True"/> 
                   </StackPanel> 
                 </DockPanel> 
                 <Expander Header="Notes" 
                           Padding="5" 
                           TextElement.Foreground="{TemplateBinding Foreground}"> 
                   <xcdg:DataCell FieldName="Notes" 
                                  Template="{StaticResource titleLessCell}"/> 
                 </Expander> 
               </StackPanel> 
             </Grid> 
           </Border> 
         </ControlTemplate> 
       </Setter.Value> 
     </Setter> 
     <Setter Property="FocusVisualStyle" 
             Value="{x:Null}"/> 
   </Style> 
 </Grid.Resources> 
 <xcdg:DataGridControl x:Name="OrdersGrid" 
                       ItemsSource="{Binding Source={StaticResource cvs_employees}}" 
                       ItemContainerStyle="{StaticResource customCardViewDataRow}" 
                       View="CardView"> 
   <xcdg:DataGridControl.Columns> 
     <xcdg:Column FieldName="Notes" 
                  TextWrapping="Wrap"/> 
   </xcdg:DataGridControl.Columns> 
 </xcdg:DataGridControl> 
</Grid>

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.

Fixed Columns vs. Templates This feature is available only in the Professional Edition

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.

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

Supported Operating Systems: Windows Server 2003 Service Pack 1; Windows Vista; Windows XP Service Pack 2

See Also