LookUpEditBase.ProcessNewValue Event

Occurs when a new value entered into the edit box is validated.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v20.1.dll

Declaration

[DXCategory("Events")]
public event ProcessNewValueEventHandler ProcessNewValue
<DXCategory("Events")>
Public Event ProcessNewValue As ProcessNewValueEventHandler

Event Data

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

Property Description
DisplayValue Gets or sets the value entered by the end-user.
Handled Gets or sets a value specifying whether the lookup editor must locate the newly inserted record.

Remarks

The editor's ProcessNewValue event is equivalent to the RepositoryItemLookUpEditBase.ProcessNewValue event available via the LookUpEditBase.Properties object, i.e. adding/removing an event handler for the current event actually affects the RepositoryItemLookUpEditBase.ProcessNewValue event.

Refer to the RepositoryItemLookUpEditBase.ProcessNewValue topic for more information.

Examples

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:

LookupEdit_ProcessNewValue_example_Confirm

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

LookupEdit_ProcessNewValue_example_EntryAdded

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