EditBeginning Event
See Also  Example
Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace > Cell Class : EditBeginning Event

Raised when the BeginEdit method has been called to signal that the edit process is about to begin.

Syntax

Visual Basic (Declaration) 
Public Event EditBeginning() As CancelRoutedEventHandler
C# 
public event CancelRoutedEventHandler EditBeginning()

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 subscribe to the Cell.EditBeginning and EditBegun events as well as how to handle and cancel them.
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:DataGridControl}"> 
        <EventSetter Event="xcdg:Cell.EditBeginning" 
                     Handler="EditBeginning" /> 
        <EventSetter Event="xcdg:Cell.EditBegun" 
                     Handler="EditBegun" /> 
      </Style> 
 
      <Style TargetType="{x:Type xcdg:DataRow}"> 
         <EventSetter Event="xcdg:Cell.EditBeginning" 
                      Handler="EditBeginning" /> 
         <EventSetter Event="xcdg:Cell.EditBegun" 
                      Handler="EditBegun" /> 
      </Style> 
   </Grid.Resources> 
   <DockPanel> 
      <StackPanel DockPanel.Dock="Top"> 
         <CheckBox x:Name="handledByRowCheckBox" 
                   Content="Events are handled by the rows" 
                   IsChecked="False" /> 
         <CheckBox x:Name="cancelBeginEdit" 
                   Content="Cancel BeginEdit event" 
                   IsChecked="False" /> 
      </StackPanel> 
      <xcdg:DataGridControl x:Name="OrdersGrid" 
                            ItemsSource="{Binding Source={StaticResource cvs_orders}}" /> 
   </DockPanel> 
</Grid>
The following code provides the implementation of the EditBeginning and EditBegun event handlers.
Visual BasicCopy Code
Public Sub EditBeginning( ByVal sender As Object, ByVal e As CancelRoutedEventArgs )
   If Me.cancelBeginEdit.IsChecked = True Then
      e.Cancel = True
   End If
   If Me.handledByRowCheckBox.IsChecked = True Then
     e.Handled = True
   End If
   Debug.WriteLine( sender + ": EditBeginning" )
End Sub

Public Sub EditBegun( ByVal sender As Object, ByVal e As RoutedEventArgs )
   If Me.handledByRowCheckBox.IsChecked = True Then
     e.Handled = True
   End If
   Debug.WriteLine( sender + ": EditBegun" )
End Sub
The following code provides the implementation of the EditBeginning and EditBegun event handlers.
C#Copy Code
public void EditBeginning( object sender, CancelRoutedEventArgs e )
{
 e.Cancel = (
this.cancelBeginEdit.IsChecked == true );
 e.Handled = (
this.handledByRowCheckBox.IsChecked == true );
 Debug.WriteLine( sender +
": EditBeginning" );
}

public void EditBegun( object sender, RoutedEventArgs e )
{
 e.Handled = (
this.handledByRowCheckBox.IsChecked ?? true );
 Debug.WriteLine( sender +
": EditBegun" );
}

Remarks

The EditBeginning and EditEnding events are raised immediately after their respective BeginEdit and EndEdit methods are called to allow the process to be canceled. In the EditBeginning event, if the Cancel property of the CancelRoutedEventArgs received as a parameter is set to true, the cell or row that raised the event will be prevented from entering edit mode. Likewise, if Cancel is set to true in the EditEnding event, the cell or row will be prevented from exiting edit mode.

Notes

Setting Cancel to true does not indicate that the event has been handled. In order to handle the event Handled must also be set to true.

Requirements

Supported Frameworks: Microsoft .NET Framework version 3.5

See Also