How to: Add Value Entered by User to LookUpEdit's Data Source

  • 4 minutes to read

Suppose a lookup editor displays a list of persons in the dropdown window. Dropdown rows are retrieved from a collection of a custom ContactList class. For this purpose, the RepositoryItemLookUpEditBase.DataSource property is set to an instance of the ContactList collection.

Each element in the collection represents an object of the Contact class.

The following LookUpEditBase.ProcessNewValue event handler adds new records to the data source. This occurs when the end-user enters a new name in the edit box that does not exist in the dropdown list and presses the Enter key. The entry is added by the Add method implemented in the ContactList class. The ProcessNewValueEventArgs.Handled parameter is set to true in order to force the editor to locate the newly inserted record after the event handler is performed.

Before inserting a new record, a message box is displayed and this allows the user to submit or discard the value. The following message box appears when a 'Jack Cooper' entry is entered:


After pressing the 'Yes' button, the new string is added to the list and the editor picks it up:


using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;

//ProcessNewValue event handler
void LookUpEdit1_ProcessNewValue(object sender, ProcessNewValueEventArgs e) {
    if ((string)e.DisplayValue != String.Empty && MessageBox.Show(
        this, "Add the '" + e.DisplayValue.ToString() + "' entry to the list?",
        "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) {
            ContactList list = (sender as LookUpEdit).Properties.DataSource as ContactList;
            list.Add(new Contact(list.Count, e.DisplayValue.ToString()));
            e.Handled = true;

private void Form1_Load(object sender, EventArgs e) {
    //create a contact list 
    ContactList cList = new ContactList();
    cList.Add(new Contact(0, "John Doe"));
    cList.Add(new Contact(1, "Sam Hill"));
    cList.Add(new Contact(2, "Karen Holmes"));
    cList.Add(new Contact(3, "Bobbie Valentine"));
    cList.Add(new Contact(4, "Frank Frankson"));

    //bind the lookup editor to the list
    lookUpEdit1.Properties.DataSource = cList;
    lookUpEdit1.Properties.DisplayMember = "Name";
    lookUpEdit1.Properties.ValueMember = "Id";
    // Add columns.
    // The ID column is populated 
    // via the GetNotInListValue event (not listed in the example).
    lookUpEdit1.Properties.Columns.Add(new LookUpColumnInfo("Id", "ID", 20));
    lookUpEdit1.Properties.Columns.Add(new LookUpColumnInfo("Name", "Name", 80));
    //enable text editing
    lookUpEdit1.Properties.TextEditStyle = TextEditStyles.Standard;

public class ContactList : System.Collections.CollectionBase {
    public Contact this[int index] {
        get { return (Contact)(List[index]); }
        set { List[index] = value; }

    public int Add(Contact value) {
        return List.Add(value);

public class Contact {
    private string name;
    private int id;

    public Contact(int _id, string _name) {
        id = _id;
        name = _name;

    public string Name {
        get { return name; }
        set { name = value; }

    public int Id {
        get { return id; }
        set { id = value; }