'Declaration Public Event EditBeginning As CancelRoutedEventHandler
'Usage Dim instance As Cell Dim handler As CancelRoutedEventHandler AddHandler instance.EditBeginning, handler
public event CancelRoutedEventHandler EditBeginning
Event Data
The event handler receives an argument of type CancelRoutedEventArgs containing data related to this event. The following CancelRoutedEventArgs properties provide information specific to this event.
Property | Description |
---|---|
Cancel | Gets or sets a value that allows the routed event to be canceled. |
Handled | (Inherited from System.Windows.RoutedEventArgs) |
OriginalSource | (Inherited from ) |
RoutedEvent | (Inherited from ) |
Source | (Inherited from ) |
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.
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.
<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> <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}}" xcdg:Cell.EditBeginning="EditBeginning" xcdg:Cell.EditBegun="EditBegun"/> </DockPanel> </Grid>
The following code provides the implementation of the EditBeginning and EditBegun event handlers.
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.
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" ); }
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