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