DataLayoutControl.FieldRetrieving Event

Fires before a layout item with an embedded editor is generated and thus, prior to the editor's data binding. It allows you to customize the type of editor to be generated, modify editor binding settings and hide certain editors.

Namespace: DevExpress.XtraDataLayout

Assembly: DevExpress.XtraLayout.v20.1.dll


public event EventHandler<FieldRetrievingEventArgs> FieldRetrieving
Public Event FieldRetrieving As EventHandler(Of FieldRetrievingEventArgs)

Event Data

The FieldRetrieving event's data class is FieldRetrievingEventArgs. The following properties provide information specific to this event:

Property Description
DataSourceNullValue Gets or sets the value used to initialize the Binding.DataSourceNullValue property for the auto-generated editor.
DataSourceUpdateMode Gets or sets the value used to initialize the Binding.DataSourceUpdateMode property for the auto-generated editor.
DataType Gets the bound field's data type.
EditorType Gets or sets the type of the editor to be created.
FieldName Gets the data source field to which the editor is bound.
Handled Gets or sets whether the event is handled and the customized event parameters must be applied after the event handler is completed.
PropertyName Gets or sets the name of the editor's property to which the data source field is bound.
Visible Gets or sets the layout item's (editor's) visibility.


The FieldRetrieving event fires before layout items and editors are created at runtime in the following cases:

The FieldRetrieving event fires for each public field in the underlying data source. Handle this event to customize the type of editor to be generated, modify editor binding settings and to hide certain editors (hidden layout items will be accessible at runtime from the Customization Form).

For changes made in the FieldRetrieving event to be in effect, set the event's Handled parameter to true.


This example shows how to handle the DataLayoutControl.FieldRetrieving and DataLayoutControl.FieldRetrieved events to customize binding information, and settings of auto-generated layout items and embedded editors.

In the example, the DataLayoutControl.FieldRetrieving event is handled to assign a ComboBoxEdit control for editing the ZipCode field. Items are added to the ComboBoxEdit after the editor is created (in the DataLayoutControl.FieldRetrieved event).

In the DataLayoutControl.FieldRetrieving event handler, the DataSourceUpdateMode parameter is set to OnPropertyChanged. For instance, this forces the "Full Name" field to be updated immediately on typing text in the "First Name" and "Last Name" fields.

The following image shows the result:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;

namespace DataLayoutControl_FieldRetrieve {
    public partial class Form1 : Form {
        public Form1() {

        private void Form1_Load(object sender, EventArgs e) {
            BindingSource personBindingSource = new BindingSource();
            personBindingSource.DataSource = typeof(Person);

            dataLayoutControl1.FieldRetrieving += dataLayoutControl1_FieldRetrieving;
            dataLayoutControl1.FieldRetrieved += dataLayoutControl1_FieldRetrieved;
            dataLayoutControl1.DataSource = personBindingSource;


        void dataLayoutControl1_FieldRetrieving(object sender, DevExpress.XtraDataLayout.FieldRetrievingEventArgs e) {
            if (e.FieldName == "ZipCode") 
                e.EditorType = typeof(ComboBoxEdit);
            e.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
            e.Handled = true;

        void dataLayoutControl1_FieldRetrieved(object sender, DevExpress.XtraDataLayout.FieldRetrievedEventArgs e) {
            if (e.FieldName == "FirstName" || e.FieldName == "LastName") {
                e.Control.BackColor = Color.GreenYellow;
            if (e.FieldName == "ZipCode") {
                RepositoryItemComboBox riComboBox = e.RepositoryItem as RepositoryItemComboBox;
                riComboBox.TextEditStyle = TextEditStyles.DisableTextEditor;

    public class Person {
        [Display(GroupName = "<GroupName->")]
        public string FirstName { get; set; }
        [Display(GroupName = "<GroupName->")]
        public string LastName { get; set; }
        public string FullName { get { return FirstName + " " + LastName; } }
        [Display(GroupName = "<GroupPhone->")]
        public string Phone { get; set; }
        [Display(GroupName = "<GroupPhone->")]
        public string Email { get; set; }
        [Display(GroupName = "Address")]
        public string City { get; set; }
        [Display(GroupName = "Address")]
        public string ZipCode { get; set; }

See Also