# Events

The DataForm exposes a set of events that are raised on different occasions.

* `AutoGeneratingField`—Fires during the automatic creation of a data field. The event is raised for each data field that will be created and can be used to modify or replace the field. The event arguments are of type `AutoGeneratingFieldEventArgs` and provide access to information for the edited property, the display index of the data field, and the data field itself.

#### **AutoGeneratingField Event Handler**

```C#
private void RadDataForm_AutoGeneratingField(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
{
	DataFormDataField datafield = e.DataField;
	int? displayIndex = e.Order;
	string propertyName = e.PropertyName;
	Type propertyType = e.PropertyType;

	if (propertyName == "PropertyThatShouldNotBePresentedInTheUI")
	{
		e.Cancel = true;
	}
}
```

* `DataFieldPreparedEditor`—Fires when the editor of the associated data field is created. The event arguments are of type `DataFieldPreparedEditorEventArgs`, which provide information about the editor and the data field object.

#### **DataFieldPreparedEditor Event Handler**

```C#
private void RadDataForm_DataFieldPreparedEditor(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.DataFieldPreparedEditorEventArgs e)
{
	DataFormDataField datafield = e.DataField;
	FrameworkElement editor = e.Editor;
}
```

* `CurrentItemChanged`—Fires when the currently selected item changes.

* `InitializingNewItem`—Fires when the creation of a new item begins. The event arguments are of type `InitializingNewItemEventArgs`, which allows you to replace or edit the created item, or cancel the creation.

#### **InitializingNewItem Event Handler**

```C#
private void RadDataForm_InitializingNewItem(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.InitializingNewItemEventArgs e)
{
	e.DataItem = new MyDataItem();
}
```

* `AddingNewItem`—Fires when a new item is added through the UI or the API of the component. The event arguments are of type `AddingNewItemEventArgs`, which can be used to cancel the adding of the item.

#### **AddingNewItem Event Handler**

```C#
private void RadDataForm_AddingNewItem(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.AddingNewItemEventArgs e)
{
	if (shouldNotAllowNewItemAdding)
	{
		e.Cancel = true;
	}
}
```

* `AddedNewItem`—Fires after a new item is added in the `ItemsSource` through the UI or the API of the component. The event arguments are of type `AddedNewItemEventArgs` and contain information about the newly added item.

#### **AddedNewItem Event Handler**

```C#
private void RadDataForm_AddedNewItem(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.AddedNewItemEventArgs e)
{
	object addedItem = e.NewItem;
}
```

* `DeletingItem`—Fires when an item is deleted through the UI or the API of the component. The event arguments are of type `CancelEventArgs`, which can be used to cancel the deletion of the item.

#### **DeletingItem Event Handler**

```C#
private void RadDataForm_DeletingItem(object sender, CancelEventArgs e)
{
	if (shouldNotAllowItemDeleting)
	{
		e.Cancel = true;
	}
}
```

* `DeletedItem`—Fires after an item was deleted through the UI or the API of the component. The event arguments are of type `ItemDeletedEventArgs`, which provides access to the deleted item.

#### **DeletedItem Event Handler**

```C#
private void RadDataForm_DeletedItem(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.ItemDeletedEventArgs e)
{
	object removedItem = e.DeletedItem;
}
```

* `BeginningEdit`—Fires when editing is beginning. The event arguments are of type `CancelEventArgs`, which can be used to cancel the beginning of the item edit.

#### **BeginningEdit Event Handler**

```C#
private void RadDataForm_BeginningEdit(object sender, CancelEventArgs e)
{
	if (shouldNotAllowEditStart)
	{
		e.Cancel = true;
	}
}
```

* `EditEnding`—Fires when editing is ending. The event arguments are of type `EditEndingEventArgs`, which can be used to cancel the ending of the item edit and also to get the edit action (cancel or commit).

#### **EditEnding Event Handler**

```C#
private void RadDataForm_EditEnding(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.EditEndingEventArgs e)
{
	EditAction action = e.EditAction;
	if (shouldCancelEditEnded)
	{
		e.Cancel = true;
	}
}
```

* `EditEnded`—Fires after editing ends. The event arguments are of type `EditEndedEventArgs`, which allows you to get the edit action (cancel or commit).

#### **EditEnded Event Handler**

```C#
private void RadDataForm_EditEnded(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.EditEndedEventArgs e)
{
	EditAction action = e.EditAction;
}
```

* `DataFieldBeginningEdit`—Fires when the editing of the data field is beginning. The event arguments are of type `DataFieldCancelEventArgs`, which allows you to cancel the editing and also to get the associated data field object.

#### **DataFieldBeginningEdit Event Handler**

```C#
private void RadDataForm_DataFieldBeginningEdit(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.DataFieldCancelEventArgs e)
{
	DataFormDataField datafield = e.DataField;
	if (shouldCancelEditStart)
	{
		e.Cancel = true;
	}
}
```

* `DataFieldEditEnded`—Fires after editing ends. The event arguments are of type `DataFieldEditEndedEventArgs`, which allows you to get the edit action (cancel or commit) and also the previous and new values.

#### **DataFieldEditEnded Event Handler**

```C#
private void dataForm_DataFieldEditEnded(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.DataFieldEditEndedEventArgs e)
{
	DataFormDataField datafield = e.DataField;
	EditAction action = e.EditAction;
	object newValue = e.NewValue;
	object previousValue = e.OldValue;
}
```

* `ValidatingItem`—Fires when an item is being validated. The event arguments are of type `CancelEventArgs`, which can be used to cancel the validation of the item.

#### **ValidatingItem Event Handler**

```C#
private void RadDataForm_ValidatingItem(object sender, CancelEventArgs e)
{
	if (shouldCancelItemValidating)
	{
		e.Cancel = true;
	}
}
```

* `DataFieldValidating`—Fires when a data field value is being validated. The event arguments are of type `DataFieldValidatingEventArgs`, which provide information about the validation state of the field and also about the new and old value in the editor.

#### **DataFieldValidating Event Handler**

```C#
private void RadDataForm_DataFieldValidating(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.DataFieldValidatingEventArgs e)
{
	DataFormDataField datafield = e.DataField;
	object newValue = e.NewValue;
	object previousValue = e.OldValue;
	IEnumerable<ValidationResult> results = e.ValidationResults;

	if (!isTheDataFieldValid)
	{
		e.IsValid = false;
	}            
}
```

* `DataFieldValidated`—Fires after the data field validation ends. The event arguments are of type `DataFieldValidatedEventArgs`, which provide information about the validation results and also about the data field object.

#### **DataFieldValidated Event Handler**

```C#
private void RadDataForm_DataFieldValidated(object sender, Telerik.UI.Xaml.Controls.Data.DataForm.DataFieldValidatedEventArgs e)
{
   DataFormDataField datafield = e.DataField;
   IEnumerable<ValidationResult> results = e.ValidationResults;
}
```

## See Also

* [Getting Started with the Telerik UI for WinUI DataForm](https://www.telerik.com/winui/documentation/controls/raddataform/getting-started)
* [Visual Structure](https://www.telerik.com/winui/documentation/controls/raddataform/visual-structure)
