Skip to main content
A newer version of this page is available. .

RepositoryItemLookUpEditBase.ProcessNewValue Event

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

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v19.2.dll

Declaration

[DXCategory("Events")]
public event ProcessNewValueEventHandler ProcessNewValue

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

End-users can type new values into a lookup editor provided that the RepositoryItemLookUpEditBase.TextEditStyle property is set to TextEditStyles.Standard. When an end-user presses the Enter key or moves focus to another control, the editor searches for the row whose RepositoryItemLookUpEditBase.DisplayMember field value matches the typed text. If such a row is not found, the ProcessNewValue event is fired.

If a record matching the typed text is found, the event does not occur.

You can handle the ProcessNewValue event to add a new record representing the new text. If you add a record, you need to set the ProcessNewValueEventArgs.Handled property of the event parameter to true. This will force the editor to locate and select the newly inserted record.

Note

If the type of the data field specified by the RepositoryItemLookUpEditBase.DisplayMember property is not convertable from the String type, the LookUpEdit will not be able to locate the new record using the text inserted by the user. To overcome this issue, manually set the event’s DisplayValue parameter to the new value stored in the RepositoryItemLookUpEditBase.DisplayMember field of the newly added record.

If you do not want to add a new record or you do not want the LookUpEdit to locate your new record, leave the ProcessNewValueEventArgs.Handled parameter set to false.

Note

The ProcessNewValue event may not function properly if the underlying data source does not support change notifications (specifically, if it does not provide the ListChanged event).

The editor’s LookUpEditBase.ProcessNewValue event is equivalent to the current event.

Example

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