# Properties, Events and Attributes

## Properties

The main purpose of **RadDataEntry** is to generate editors according to the object properties and to create simple data bindings for them. For this reason, most of the control properties will take effect only if they are set **before setting the DataSource.**

* The most important property of **RadDataEntry** is **DataSource**. Through this property user can set the business object or a collection of objects that should be editing. When this property is set **RadDataEntry** generates editors for each public property which does not have its **Browsable** attribute set to *false.*

### RadDataEntry Binding.

```C#
this.radDataEntry1.DataSource = new Employee() 
{ 
    FirstName = "Sarah",
    LastName = "Blake",
    Occupation = "Supplied Manager", 
    StartingDate = new DateTime(2005, 04, 12),
    IsMarried = true, 
    Salary = 3500, Gender = Gender.Female 
};
```

```VB.NET
Me.radDataEntry1.DataSource = New Employee() With { _
  .FirstName = "Sarah", _
  .LastName = "Blake", _
  .Occupation = "Supplied Manager", _
  .StartingDate = New DateTime(2005, 4, 12), _
  .IsMarried = True, _
  .Salary = 3500, _
  .Gender = Gender.Female _
 }
```

> caption> Figure 1: Set The Data Source of RadDataEntry

![WinForms RadDataEntry Set The Data Source of RadDataEntry](https://www.telerik.com/products/winforms/documentation/assets/7720c820553be098e4651a0c92598f8e/dataentry-properties-events-and-attributes001.png)

* The **ColumnCount** property controls the amount of columns that **RadDataEntry** will use to arrange generated controls. Default value is 1

### Set the Columns Count.

```C#
this.radDataEntry1.ColumnCount = 2;
```

```VB.NET
Me.radDataEntry1.ColumnCount = 2
```

> caption Figure 2: Set The Columns Count.

![WinForms RadDataEntry Set The Columns Count](https://www.telerik.com/products/winforms/documentation/assets/65bb15d366c432b31652d68772fa0559/dataentry-properties-events-and-attributes002.png)

* The **FitToParentWidth** property controls whether the generated editors should fit their width to width of the **RadDataEntry**. Default Value is *false*.

### Set FitToParentWidth Property.

```C#
this.radDataEntry1.FitToParentWidth = true;
```

```VB.NET
Me.radDataEntry1.FitToParentWidth = True
```

> caption Figure 3. Set FitToParentWidth

![WinForms RadDataEntry Set FitToParentWidth](https://www.telerik.com/products/winforms/documentation/assets/a12b4a56b076086723f7d4b9a727afa8/dataentry-properties-events-and-attributes003.png)

* The **ShowValidationPanel** property controls the visibility of validation panel. Please note that this property will change the visibility of panel if only there are controls inside it. By default this panel is disabled.

### Setup the Validation Panel.

```C#

this.radDataEntry1.ShowValidationPanel = true;

RadLabel label = new RadLabel();
label.Name = "First Name";
label.Text = "<html><size=10><b>First Name : </b>First Name should be between 2 and 15 chars long.";
label.Dock = DockStyle.Top;
label.AutoSize = false;
label.BackColor = Color.Transparent;
this.radDataEntry1.ValidationPanel.PanelContainer.Controls.Add(label);

```

```VB.NET

Me.radDataEntry1.ShowValidationPanel = True

Dim label As New RadLabel()
label.Name = "First Name"
label.Text = "<html><size=10><b>First Name : </b>First Name should be between 2 and 15 chars long."
label.Dock = DockStyle.Top
label.AutoSize = False
label.BackColor = Color.Transparent
Me.radDataEntry1.ValidationPanel.PanelContainer.Controls.Add(label)

```

> caption Figure 4: The Validation Panel.

![WinForms RadDataEntry The Validation Panel](https://www.telerik.com/products/winforms/documentation/assets/a591e7c82bcbc472906ba0adad36e657/dataentry-properties-events-and-attributes004.png)

* The **FlowDirection** controls the direction the editors will be generated when the **ColumnCount** property has value bigger than 1.

### Set the Flow Direction.

```C#
this.radDataEntry1.ColumnCount = 2;
this.radDataEntry1.FlowDirection = FlowDirection.BottomUp;
```

```VB.NET
Me.radDataEntry1.ColumnCount = 2
Me.radDataEntry1.FlowDirection = FlowDirection.BottomUp
```

> caption Figure 5: Set the flow direction.

![WinForms RadDataEntry Set the Flow Direction](https://www.telerik.com/products/winforms/documentation/assets/bdebb593fb3fb72d3a29ab30fac2a1a3/dataentry-properties-events-and-attributes005.png)

* The **ItemSpace** property controls the space that between the generated items. Default value is 5 pixels.

#### Set Space Between The Items.

```C#
this.radDataEntry1.ItemSpace = 10;
```

```VB.NET
Me.radDataEntry1.ItemSpace = 10
```

> caption Figure 6 Set the items space.

![WinForms RadDataEntry Set the Items Space](https://www.telerik.com/products/winforms/documentation/assets/f82d2f67140bc0cb428b2da4b7330c17/dataentry-properties-events-and-attributes006.png)

* The **ItemDefaultSize** property sets the size that generated items should have if **FitToParentWidth** property has value *false*. When property the **FitToParentWidth** has value *true* the width of items are calculated according the width of the **RadDataEntry** control and the number of the columns. In this case the width defined with **ItemDefaultSize** is ignored.

#### Set items default size.

```C#
this.radDataEntry1.ItemDefaultSize = new Size(300, 30);
```

```VB.NET
Me.radDataEntry1.ItemDefaultSize = New Size(300, 30)
```

> caption Figure 7. Set items size.

![WinForms RadDataEntry Set Items Size](https://www.telerik.com/products/winforms/documentation/assets/ab9d4ada5221573d9699678021069f4d/dataentry-properties-events-and-attributes007.png)

* In **RadDataEntry** control there is logic that arranges the labels of the editors in one column according to the longest text. This logic can be controlled by the **AutoSizeLabels** property. By default the property value is **false** and the labels width will equals the longest label width. If you set this property to **true**, the labels will be sized according to their content, as shown on the following figure:

#### Set The AutoSizeLabels Property.

```C#
this.radDataEntry1.AutoSizeLabels = true;
```

```VB.NET
Me.radDataEntry1.AutoSizeLabels = True
```

> caption Figure 8: The Labels are not Auto-Sized.

![WinForms RadDataEntry The labels are not Auto-Sized](https://www.telerik.com/products/winforms/documentation/assets/2491d42e1944da2ba29c239b8bbc742f/dataentry-properties-events-and-attributes008.png)

## Events

There are several events that you will find useful in the context of **RadDataEntry**:

**EditorInitializing** - Occurs when editor is being initialized. This event is cancelable. In this event you can change the default editors with custom ones.

**EditorInitialized**  - Occurs when the editor is Initialized.

**BindingCreating** - Occurs when a binding object for an editor is about to be created. This event is cancelable.

**BindingCreated** - Occurs when binding object is created.

**ItemInitializing** – this event is firing when the panel that contains the label, editor and validation label is about to be Initialized. This event is cancelable.

**ItemInitialized** - occurs the item is already Initialized.

**ItemValidating** – this event is fired when any of the generated editors fires its Validating event.

**ItemValidated** – this event is fired when any of the generated editors fires its Validated event.

## Attributes

**RadDataEntry** has support for several attributes that can be used to change the behavior of the control.

With the **Browsable** attribute users can easily control which properties should be displayed

> note The **Browsable** attribute set to *false* will make the property on which it is used not bindable. This will prevent other controls which use the [CurrencyManager](https://msdn.microsoft.com/en-us/library/system.windows.forms.currencymanager\(v=vs.110\).aspx) for extracting properties to bind to such a class. A suitable solution for this scenario is to leave the property **Browsable** set to *true* and handle the **RadDataEntry**.*ItemInitializing* setting the e.Cancel property to *true* for items which need to hidden in **RadDataEntry**.

### Set The Browsable Attribute.

```C#
[Browsable(false)]
public string PhoneNumber
{
    get;
    set;
}
```

```VB.NET
            <Browsable(False)> _
            Public Property PhoneNumber() As String
                Get
                    Return m_PhoneNumber
                End Get
                Set(value As String)
                    m_PhoneNumber = Value
                End Set
            End Property
            Private m_PhoneNumber As String
```

The **DisplayName** attribute defines what text should be displayed in the label that is associated with the editor.

### Set The DisplayName Attribute.

```C#
[DisplayName("family name")]
public string LastName
{
    get;
    set;
}
```

```VB.NET
            <DisplayName("family name")> _
            Public Property LastName() As String
                Get
                    Return m_LastName
                End Get
                Set(value As String)
                    m_LastName = Value
                End Set
            End Property
            Private m_LastName As String
```

![WinForms RadDataEntry Set The DisplayName Attribute](https://www.telerik.com/products/winforms/documentation/assets/85bf4cc0fab1502b9fa7930f1e2428b6/dataentry-properties-events-and-attributes009.png)

With **RadRange** attribute users can define range that can be used into validation process. This attribute is provided in validation events.

### Set The RadRange Attribute

```C#
[RadRange(1500,2000)]
public int Salary
{
    get;
    set;
}
```

```VB.NET
            <RadRange(1500, 2000)> _
            Public Property Salary() As Integer
                Get
                    Return m_Salary
                End Get
                Set(value As Integer)
                    m_Salary = Value
                End Set
            End Property
            Private m_Salary As Integer
```

## See Also

* [Structure](https://www.telerik.com/products/winforms/documentation/controls/dataentry/control-element-structure-)
* [Getting Started](https://www.telerik.com/products/winforms/documentation/controls/dataentry/getting-started)
* [Validation](https://www.telerik.com/products/winforms/documentation/controls/dataentry/validation)
* [Themes](https://www.telerik.com/products/winforms/documentation/controls/dataentry/customizing-appearance/themes)
* [Change the editor to RadDropDownList](https://www.telerik.com/products/winforms/documentation/controls/dataentry/how-to/change-the-editor-to-a-bound-raddropdownlist)
