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

Contains the information required to display the template that will be used to edit the content of a cell as well as the activation gestures that activation the template.

Object Model


Syntax

Visual Basic (Declaration) 
Public Class CellEditor 
   Inherits Freezable
   Implements ISealable 
C# 
public class CellEditor : Freezable, ISealable  

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 examples demonstrates how to change the edit template of the cell editor for the ShipVia column to a Slider control.
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}"/> 
  </Grid.Resources> 
  <xcdg:DataGridControl x:Name="OrdersGrid" 
                        ItemsSource="{Binding Source={StaticResource cvs_orders}}"> 
    <xcdg:DataGridControl.Columns> 
 
     <xcdg:Column FieldName="ShipVia"> 
       <xcdg:Column.CellEditor> 
         <xcdg:CellEditor> 
           <xcdg:CellEditor.EditTemplate> 
             <DataTemplate> 
               <Slider Value="{xcdg:CellEditorBinding}" Minimum="1" Maximum="3"/> 
             </DataTemplate> 
           </xcdg:CellEditor.EditTemplate> 
           <xcdg:CellEditor.ActivationGestures> 
             <xcdg:KeyActivationGesture Key="Right"/> 
             <xcdg:KeyActivationGesture Key="Left"/> 
           </xcdg:CellEditor.ActivationGestures> 
         </xcdg:CellEditor> 
       </xcdg:Column.CellEditor> 
     </xcdg:Column> 
    </xcdg:DataGridControl.Columns> 
  </xcdg:DataGridControl> 
</Grid>
The following example demonstrates how to change the edit template of the cell editor for the Freight column to a custom calculator control. The C# code for the Calculate method called in the buttons' Click event simply calculates the new equation and is not provided. To shorten the code, some of the Button and KeyActivationGesture declarations have been removed.
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}"/> 
  </Grid.Resources> 
   <xcdg:DataGridControl x:Name="OrdersGrid" 
                         ItemsSource="{Binding Source={StaticResource cvs_orders}}"> 
      <xcdg:DataGridControl.Columns> 
 
        <xcdg:Column FieldName="Freight"> 
           <xcdg:Column.CellEditor> 
              <xcdg:CellEditor> 
                 <xcdg:CellEditor.EditTemplate> 
                    <DataTemplate> 
                        <DockPanel> 
                           <TextBlock x:Name="actual_value" 
                                     Text="{xcdg:CellEditorBinding}" 
                                      DockPanel.Dock="Top"/> 
                           <UniformGrid Columns="4" x:Name="parentPanel" 
                                        Tag="{Binding ElementName=actual_value, 
                                                      Path=Text, 
                                                      Mode=TwoWay, 
                                                      UpdateSourceTrigger=PropertyChanged}" 
                                        Button.Click="Calculate" 
                                        DockPanel.Dock="Top"> 
                              <Button x:Name="seven" Content="7"/> 
                              <!-- ... --> 
                              <Button x:Name="addition" Content="+"/> 
                           </UniformGrid> 
                           <TextBlock x:Name="current_equation" DockPanel.Dock="Bottom"/> 
                         </DockPanel> 
                     </DataTemplate> 
                 </xcdg:CellEditor.EditTemplate> 
                 <xcdg:CellEditor.ActivationGestures> 
                    <xcdg:KeyActivationGesture Key="NumPad0"/> 
                    <!-- ... --> 
                    <xcdg:KeyActivationGesture Key="NumPad9"/> 
                 </xcdg:CellEditor.ActivationGestures> 
              </xcdg:CellEditor> 
           </xcdg:Column.CellEditor> 
        </xcdg:Column> 
      </xcdg:DataGridControl.Columns> 
   </xcdg:DataGridControl> 
</Grid>
The following example demonstrates how to provide a default cell editor for columns that have an Int32 data type.
XAMLCopy Code
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid" 
      xmlns:s="clr-namespace:System;assembly=mscorlib"> 
  <Grid.Resources> 
    <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.DefaultCellEditors> 
     <xcdg:CellEditor x:Key="{x:Type s:Int32}"> 
       <xcdg:CellEditor.EditTemplate> 
         <DataTemplate> 
           <Slider Value="{xcdg:CellEditorBinding}"/> 
         </DataTemplate> 
       </xcdg:CellEditor.EditTemplate> 
     </xcdg:CellEditor> 
   </xcdg:DataGridControl.DefaultCellEditors> 
  </xcdg:DataGridControl> 
</Grid>

Remarks

The data template that will be used to edit the content of a cell is specified through the EditTemplate property while the activation gestures that are supported by the CellEditor are contained in the ActivationGestures collection.

Custom cell editors can be provided per column by setting a column's CellEditor property, or per data type through the DataGridControl.DefaultCellEditors property.

Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Freezable
            Xceed.Wpf.DataGrid.CellEditor

Requirements

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

See Also