# Events

This article lists the events specific for **RadCardView**.

* **AutoGeneratingDataFieldDescriptor**: Occurs when a DataFieldDescriptor is autogenerating. A descriptor is generated for each public property of the card's data item. The event can be used to customize or cancel the creation of data fields. The event arguments are of type `CardViewAutoGeneratingDataFieldDescriptorEventArgs` which expose the following members:

  * **DataFieldDescriptor**: Gets the associated data field descriptor object.
  * **ItemPropertyInfo**: Gets the associated item property info.

  **Example 1: AutoGeneratingDataFieldDescriptor event handler**

```C#
private void RadCardView_AutoGeneratingDataFieldDescriptor(object sender, CardViewAutoGeneratingDataFieldDescriptorEventArgs e)
{
    bool isCanceled = e.Cancel;
    CardDataFieldDescriptor dataFieldDescritor = e.DataFieldDescriptor;
    ItemPropertyInfo propertyInfo = e.ItemPropertyInfo;
}
```

* **CardDataFieldPreparedEditor**: Occurs when the editor control of a card's data field is prepared, just before the editing of the field starts. The event arguments are of type `CardDataFieldPreparedEditorEventArgs` which expose the following members:

  * **FrameworkElement**: Gets the control representing the editor of the data field.
  * **DataField**: Gets the associated `DataFormDataField` object.

  **Example 2: CardDataFieldPreparedEditor event handler**

```C#
private void RadCardView_CardDataFieldPreparedEditor(object sender, Telerik.Windows.Controls.Data.CardView.CardDataFieldPreparedEditorEventArgs e)
{
    RadCardViewItem card = e.CardViewItem;
    DataFormDataField dataField = e.DataField;
    FrameworkElement editor = e.Editor;
}
```

* **SelectionChanged**: Occurs when the selected card is changed. The event arguments are of type `SelectionChangedEventArgs` which expose the following members:

  * **AddedItems**: Gets a collection containing the newly selected card.
  * **RemovedItems**: Gets a collection containing the previously selected card.

  **Example 3: SelectionChanged event handler**

```C#
private void RadCardView_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
    IList addedItems = e.AddedItems;
    IList removedItems = e.RemovedItems;
}
```

## Editing

* **CardBeginningEdit**: Occurs just before an edit operation is started. The event can be used to cancel the editing by setting the event arguments **Cancel** property to `true`.  The event arguments are of type `CardViewItemCancelEventArgs` which expose the following members:

  * **CardViewItem**: Gets the associated `RadCardViewItem` object.

  **Example 4: CardBeginningEdit event handler**

```C#
private void RadCardView_CardBeginningEdit(object sender, Telerik.Windows.Controls.Data.CardView.CardViewItemCancelEventArgs e)
{
    bool isCanceled = e.Cancel;
    RadCardViewItem card = e.CardViewItem;
}
```

* **CardEditEnding**: Occurs just before an edit operation is finished. The event arguments are of type `CardDataFieldCancelEventArgs` which expose the following members:

  * **CardViewItem**: Gets the associated `RadCardViewItem` object.
  * **DataField**: Gets the associated `DataFormDataField` object.

  **Example 5: CardEditEnding event handler**

```C#
private void RadCardView_CardEditEnding(object sender, Telerik.Windows.Controls.Data.CardView.CardViewEditEndingEventArgs e)
{
    bool isCanceled = e.Cancel;
    RadCardViewItem card = e.CardViewItem;
    EditAction editAction = e.EditAction;
}
```

* **CardEditEnded**: Occurs when an edit operation is finished. The event arguments are of type `CardViewEditEndedEventArgs` which expose the following members:

  * **CardViewItem**: Gets the associated `RadCardViewItem` object.
  * **EditAction**: Gets the edit action - **Cancel** or **Commit**.

  **Example 6: CardEditEnded event handler**

```C#
private void RadCardView_CardEditEnded(object sender, CardViewEditEndedEventArgs e)
{
    RadCardViewItem card = e.CardViewItem;
    EditAction editAction = e.EditAction;
}
```

* **CardDataFieldBeginningEdit**: Occurs just before an edit operation is started for a data field. The event arguments are of type `CardDataFieldCancelEventArgs` which expose the following members:

  * **CardViewItem**: Gets the associated `RadCardViewItem` object.
  * **DataField**: Gets the associated `DataFormDataField` object.

  **Example 7: CardDataFieldBeginningEdit event handler**

```C#
private void RadCardView_CardDataFieldBeginningEdit(object sender, Telerik.Windows.Controls.Data.CardView.CardDataFieldCancelEventArgs e)
{
    bool isCanceled = e.Cancel;
    RadCardViewItem card = e.CardViewItem;
    DataFormDataField dataField = e.DataField;
}
```

* **CardDataFieldEditEnded**: Occurs when an edit operation is finished for a data field. The event arguments are of type `CardDataFieldEditEndedEventArgs` which expose the following members:

  * **CardViewItem**: Gets the associated `RadCardViewItem` object.
  * **EditAction**: Gets the edit action - **Cancel** or **Commit**.
  * **NewValue**: Gets the edited value.
  * **OldValue**: Gets the previous value.

  **Example 8: CardDataFieldEditEnded event handler**

```C#
private void RadCardView_CardDataFieldEditEnded(object sender, Telerik.Windows.Controls.Data.CardView.CardDataFieldEditEndedEventArgs e)
{
    RadCardViewItem card = e.CardViewItem;
    DataFormDataField dataField = e.DataField;
    EditAction editAction = e.EditAction;
    object oldValue = e.OldValue;
    object newValue = e.NewValue;
}
```

## Validation

* **CardValidating**: Occurs when a card is being validated. The event arguments are of type `CardViewItemCancelEventArgs` which expose the following members:

  * **CardViewItem**: Gets the associated `RadCardViewItem` object.

  **Example 9: CardValidating event handler**

```C#
private void RadCardView_CardValidating(object sender, Telerik.Windows.Controls.Data.CardView.CardViewItemCancelEventArgs e)
{
    bool isCanceled = e.Cancel;
    RadCardViewItem card = e.CardViewItem;
}
```

* **CardDataFieldValidating**: Occurs when a data field starts data validating. The event arguments are of type `CardDataFieldValidatingEventArgs` which expose the following members:

  * **IsValid**: Gets the current validating state.
  * **ValidationResults**: Gets a collection with the validation results.
  * **CardViewItem**: Gets the associated `RadCardViewItem` object.
  * **DataField**: Gets the associated `DataFormDataField` object.

  **Example 10: CardDataFieldValidating event handler**

```C#
private void RadCardView_CardDataFieldValidating(object sender, Telerik.Windows.Controls.Data.CardView.CardDataFieldValidatingEventArgs e)
{
    bool isValid = e.IsValid;
    RadCardViewItem card = e.CardViewItem;
    DataFormDataField dataField = e.DataField;
    IEnumerable<System.Windows.Controls.ValidationResult> results = e.ValidationResults;
}
```

* **CardDataFieldValidated**: Occurs when data field is being validated. The event arguments are of type `CardDataFieldEditEndedEventArgs` which expose the following members:

  * **ValidationResults**: Gets a collection with the validation results.
  * **CardViewItem**: Gets the associated `RadCardViewItem` object.
  * **DataField**: Gets the associated `DataFormDataField` object.

  **Example 11: CardDataFieldValidated event handler**

```C#
private void RadCardView_CardDataFieldValidated(object sender, Telerik.Windows.Controls.Data.CardView.CardDataFieldValidatedEventArgs e)
{
    RadCardViewItem card = e.CardViewItem;
    DataFormDataField dataField = e.DataField;
    IEnumerable<System.Windows.Controls.ValidationResult> results = e.ValidationResults;
}
```

## Filtering

* **FieldFilterEditorCreated**: Occurs when a field filter editor is created. The event arguments are of type `CardViewFilterEditorCreatedEventArgs` which expose the following members:

  * **CardDataFieldFilterDescriptor**: This property gets the corresponding `CardDataFieldFilterDescriptor` object.
  * **Editor**: Gets the control representing the editor of the data field.

  **Example 12: FieldFilterEditorCreated event handler**

```C#
private void RadCardView_FieldFilterEditorCreated(object sender, Telerik.Windows.Controls.Data.CardView.CardViewFilterEditorCreatedEventArgs e)
{
    FrameworkElement editor = e.Editor;
    CardDataFieldDescriptor dataFieldDescritor = e.CardDataFieldDescriptor;
}
```

* **Filtering**: Occurs before the filtering operation takes effect. The event can be used to cancel the filtering by setting the event arguments **Cancel** property to `true`. The event arguments are of type `CardViewFilteringEventArgs` which expose the following members:

  * **Added**: This property gets the added `IFilterDescriptor` object.
  * **Removed**: This property gets the removed `IFilterDescriptor` object.
  * **CardDataFieldFilterDescriptor**: This property gets the corresponding `CardDataFieldFilterDescriptor` object.

  **Example 13: Filtering event handler**

```C#
private void RadCardView_Filtering(object sender, Telerik.Windows.Controls.Data.CardView.CardViewFilteringEventArgs e)
{
    bool isCanceled = e.Cancel;
    IEnumerable<IFilterDescriptor> addedDescriptors = e.Added;
    IEnumerable<IFilterDescriptor> removedDescriptors = e.Removed;
    ICardDataFieldFilterDescriptor dataFieldFilterDescritor = e.CardDataFieldFilterDescriptor;
}
```

* **Filtered**: Occurs after the filtering operation is executed. The event arguments are of type `CardViewFilteredEventArgs` which expose the following members:

  * **Added**: This property gets the added `IFilterDescriptor` object.
  * **Removed**: This property gets the removed `IFilterDescriptor` object.
  * **CardDataFieldFilterDescriptor**: This property gets the corresponding `CardDataFieldFilterDescriptor` object.

  **Example 14: Filtered event handler**

```C#
private void RadCardView_Filtered(object sender, CardViewFilteredEventArgs e)
{
    IEnumerable<IFilterDescriptor> addedDescriptors = e.Added;
    IEnumerable<IFilterDescriptor> removedDescriptors = e.Removed;
    ICardDataFieldFilterDescriptor dataFieldFilterDescritor = e.CardDataFieldFilterDescriptor;
}
```

* **FilterOperatorsLoading**: Occurs before the filter operators are loaded. The event can be used to remove some of the default operators or change the currently selected one. The event arguments are of type `FilterOperatorsLoadingEventArgs` which expose the following members:

  * **AvailableOperators**: This property gets all available operators that will be displayed by default. You can remove operators from the collection in order to hide them from the UI.
  * **DefaultOperator1**: This property gets the first `FilterOperator` object.
  * **DefaultOperator2**: This property gets the second `FilterOperator` object.
  * **CardDataFieldFilterDescriptor**: This property gets the corresponding `CardDataFieldFilterDescriptor` object.

  **Example 15: FilterOperatorsLoading event handler**

```C#
private void RadCardView_FilterOperatorsLoading(object sender, FilterOperatorsLoadingEventArgs e)
{
    RemoveOnlyCollection<FilterOperator> availableOperators = e.AvailableOperators;
    CardDataFieldDescriptor dataFieldDescritor = e.CardDataFieldDescriptor;
    FilterOperator? operator1 = e.DefaultOperator1;
    FilterOperator? operator2 = e.DefaultOperator2;
}
```

* **DistinctValuesLoading**: Occurs before the distinct values of the associated data field descriptor are loaded. The event arguments are of type `CardViewDistinctValuesLoadingEventArgs` which expose the following members:

  * **ItemsSource**: Gets or sets the source collection containing the distinct values that will be loaded. This can be used to modify or replace the collection.
  * **CardDataFieldFilterDescriptor**: This property gets the corresponding `CardDataFieldFilterDescriptor` object.

  **Example 16: DistinctValuesLoading event handler**

```C#
private void RadCardView_DistinctValuesLoading(object sender, CardViewDistinctValuesLoadingEventArgs e)
{
    bool isCanceled = e.Cancel;
    CardDataFieldDescriptor dataFieldDescritor = e.CardDataFieldDescriptor;
    IEnumerable distinctValuesSource = e.ItemsSource;
}
```

## Sorting

* **Sorting**: Occurs before the sorting operation is executed. The event can be used to cancel the sorting by setting the event arguments **Cancel** property to `true`. The event arguments are of type `CardViewSortingEventArgs` which expose the following members:

  * **OldSortingState**: Gets the old sorting direction.
  * **NewSortingState**: Gets the new sorting direction.
  * **IsMultipleDataFieldDescriptorSorting**: Indicates if the current sorting is applied over multiple data field descriptors.
  * **DataFieldFilterDescriptor**: Gets the corresponding `CardDataFieldFilterDescriptor` object.

  **Example 17: Sorting event handler**

```C#
private void RadCardView_Sorting(object sender, CardViewSortingEventArgs e)
{
    bool isCanceled = e.Cancel;
    CardDataFieldDescriptor dataFieldDescritor = e.DataFieldDescriptor;
    bool isMultipleSorting = e.IsMultipleDataFieldDescriptorSorting;
    SortingState previousSortingState = e.OldSortingState;
    SortingState newSortingState = e.NewSortingState;
}
```

* **Sorted**: Occurs after the sorting operation is executed. The event arguments are of type `CardViewSortedEventArgs` which expose the following members:

  * **DataFieldFilterDescriptor**: Gets the corresponding `CardDataFieldFilterDescriptor` object.

  **Example 18: Sorted event handler**

```C#
private void RadCardView_Sorted(object sender, CardViewSortedEventArgs e)
{
    CardDataFieldDescriptor dataFieldDescritor = e.DataFieldDescriptor;
}
```

## Grouping

* **Grouping**: Occurs before the grouping operation is executed. The event can be used to cancel the grouping action by setting the event arguments **Cancel** property to `true`. The event arguments are of type `CardViewGroupingEventArgs` which expose the following members:

  * **Action**: Gets the `CardViewGroupingEventAction`.
  * **GroupDescriptor**: Gets the corresponding `IGroupDescriptor` object.
  * **Index**: Gets the group descriptor's position.

  **Example 19: Grouping event handler**

```C#
private void RadCardView_Grouping(object sender, CardViewGroupingEventArgs e)
{
    bool isCanceled = e.Cancel;
    CardViewGroupingEventAction action = e.Action;
    IGroupDescriptor groupDescriptor = e.GroupDescriptor;
    int? groupDescriptorPosition = e.Index;
}
```

* **Grouped**: Occurs after the grouping operation is executed. The event arguments are of type `CardViewGroupedEventArgs` which expose the following members:

  * **Action**: Gets the `CardViewGroupingEventAction`.
  * **GroupDescriptor**: Gets the corresponding `IGroupDescriptor` object.

  **Example 20: Grouped event handler**

```C#
private void RadCardView_Grouped(object sender, CardViewGroupedEventArgs e)
{
    CardViewGroupingEventAction action = e.Action;
    IGroupDescriptor groupDescriptor = e.GroupDescriptor;
}
```

## See Also

* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/radcardview/getting-started)
* [Visual Structure](https://www.telerik.com/products/wpf/documentation/controls/radcardview/visual-structure)
