Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

SearchLookUpEdit.AddNewValue Event

Fires when the “Add New” button is clicked, and allows you to add new records to the dropdown data source.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraGrid.v24.2.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

#Declaration

public event AddNewValueEventHandler AddNewValue

#Event Data

The AddNewValue event's data class is DevExpress.XtraEditors.Controls.AddNewValueEventArgs.

#Remarks

Display the Add New button in the editor’s dropdown to allow users to add new records. Enable the RepositoryItemSearchLookUpEdit.ShowAddNewButton option to display the button.

SearchLookUpEdit

The Search Lookup Editor fires the AddNewValue event when the user clicks the Add New button. Handle this event to add a new record to the data source.

Once a new record is created, set the e.Cancel parameter to false, and assign the key value of the new record to the e.NewValue parameter. The Search Lookup Editor locates the new record and selects it.

private void searchLookUpEdit1_AddNewValue(object sender, DevExpress.XtraEditors.Controls.AddNewValueEventArgs e) {
    // Specifies/generates a unique identifier for a new record.
    int newRecordId = { AUTO_NUMBER };
    // Shows a form that allows the user to create a new record with the 'newRecordId' and add it to the data source.
    using(XtraForm1 newRecordForm = new XtraForm1(newRecordId)) {
        // Selects a new record in the search lookup if the record was created and added to the datasource.
        if(newRecordForm.ShowDialog() == DialogResult.OK) {
            e.NewValue = newRecordId;
            e.Cancel = false;
        }
    }
}
See Also