Skip to main content

DataLayoutControl.FieldRetrieved Event

Fires after a layout is generated at runtime. Allows you to customize settings of individual generated layout items and editors.

Namespace: DevExpress.XtraDataLayout

Assembly: DevExpress.XtraLayout.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DXCategory("Data")]
public event EventHandler<FieldRetrievedEventArgs> FieldRetrieved

Event Data

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

Property Description
Control Gets the control embedded in the layout item.
FieldName Gets the data source field to which the editor is bound.
Item Gets the created Layout Item.
RepositoryItem Gets a RepositoryItem descendant that corresponds to the created editor. This property is in effect when a DevExpress editor (BaseEdit descendant) is embedded in the created layout item.

Remarks

The FieldRetrieved event fires after a layout is generated at runtime in the following cases:

The FieldRetrieved event fires for each generated layout item. Handle this event to customize settings of individual layout items and editors.

Example

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:

DataLayoutControl-FieldRetrieve-Example

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() {
            InitializeComponent();
        }

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

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

            dataLayoutControl1.RetrieveFields();
        }

        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;
                riComboBox.Items.Add("20505");
                riComboBox.Items.Add("20506");
                riComboBox.Items.Add("20507");
                riComboBox.Items.Add("20508");
                riComboBox.Items.Add("20509");
            }
        }
    }

    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; }
    }


}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FieldRetrieved event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also