# Autogenerated Fields

Generally, the RadDataForm creates its fields automatically based on the type of the corresponding properties. Thus the proper editor controls are text fields for string properties, CheckBoxes for Boolean, DateTimePickers for dates, ComboBoxes for enums.

> caption Autogenerated fields

![Autogenerated fields](https://www.telerik.com/products/wpf/documentation/assets/cd73e6bfff43bb80155ff759dedc9c4a/raddataform_bindtocollection.png)

However, you are free to change each of the fields displayed. What you need to do is to set the AutoGenerateFields property of the RadDataForm to **True** and handle the **AutoGeneratingField** event. As it is cancelable, you may reject the cretion of a particular field.

The arguments of the **AutoGeneratingField** event are:

* **Cancel**: Gets or sets a value that indicates whether the operation should be cancelled.

* **DataField**: Gets or sets the data field; it is of type DataFormDataField and depends on the type of the corresponding property. It can be:

  * **DataFormCheckBoxField**: Used for editing of boolean properties.

  * **DataFormComboBoxField**: Used for editing by choosing a value from predefined data source.

  * **DataFormDataField**: Used for editing of string properties.

  * **DataFormDateField**: Used for editing properties of type DateTime.

* **PropertyName**: Gets or sets the property name of the corresponding field.

* **PropertyType**: Gets or sets the property type of the corresponding field.

The AutoGeneratingField event will be fired for each current item, thus enabling you to customize the view on item basis.

So, for example, let us decide on defining a Description for the Salary property, set the Label of the first property to be "First Name" and define purple foreground color for the ladies and a blue one for the gentlemen:

**Example 1: Handling the AutoGeneratingField Event**

```C#
private void DataForm1_AutoGeneratingField(object sender, Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
{
    var employee = this.DataForm1.CurrentItem as Employee;
    if (e.PropertyName == "FirstName")
    {
        e.DataField.Label = "First Name";
    }
    if (e.PropertyName == "Salary")
    {
        e.DataField.Description = "This is the initial salary!";
    }
    if (employee.Gender == Gender.Female)
    {
        e.DataField.Foreground = new SolidColorBrush(Colors.Purple);
    }
    else
    {
        e.DataField.Foreground = new SolidColorBrush(Colors.Blue);
    }
}
```

```VB.NET
Public Sub DataForm1_AutoGeneratingField(sender As Object, e As Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs)
    Dim employee = TryCast(Me.DataForm1.CurrentItem, Employee)
    If e.PropertyName = "FirstName" Then
        e.DataField.Label = "First Name"
    End If
    If e.PropertyName = "Salary" Then
        e.DataField.Description = "This is the initial salary!"
    End If
    If employee.Gender = Gender.Female Then
        e.DataField.Foreground = New SolidColorBrush(Colors.Purple)
    Else
        e.DataField.Foreground = New SolidColorBrush(Colors.Blue)
    End If
End Sub
```

> caption Result of customizing the autogenerated fields

![Result of customizing the autogenerated fields #1](https://www.telerik.com/products/wpf/documentation/assets/c7b022ea2d36e2583797b9b8916ba1ca/raddataform_customizeautogeneratedfields.png)
![Result of customizing the autogenerated fields #2](https://www.telerik.com/products/wpf/documentation/assets/0cf9158143828255f158d3bc1b2b23c9/raddataform_customizeautogeneratedfields2.png)

## DataFormDateField EditorMode

The DataFormDateField is used for editing of DateTime properties. The default property editor is a control of type **RadDatePicker**. You can change this and use **RadDateTimePicker** or **RadTimePicker** by setting the **EditorMode** property.

The **EditorMode** property expects the following values:

* **Date**: RadDatePicker control will be used as a property editor .
* **Time**: RadTimePicker control will be used as a property editor.
* **DateTime**: RadDateTimePicker control will be used as a property editor.

**Example 2: Setting the EditorMode**

```C#
private void RadDataForm_AutoGeneratingField(object sender, AutoGeneratingFieldEventArgs e)
{
    if (e.DataField is DataFormDateField)
    {
        (e.DataField as DataFormDateField).EditorMode = DateFieldEditorMode.Time;
    }
}
```

```VB.NET
	Private Sub RadDataForm_AutoGeneratingField(ByVal sender As Object, ByVal e As AutoGeneratingFieldEventArgs)
		If TypeOf e.DataField Is DataFormDateField Then
			(TryCast(e.DataField, DataFormDateField)).EditorMode = DateFieldEditorMode.Time
		End If
End Sub
```

![Result of customizing the autogenerated fields #3](https://www.telerik.com/products/wpf/documentation/assets/4fc33aa3ab7f1f4b5c75a0fe235b95e7/raddataform-autogenerated-fields-0.png)

## See Also

* [AutoCommit](https://www.telerik.com/products/wpf/documentation/controls/raddataform/features/auto-commit)
