Back to Devexpress

SearchLookUpEdit.AddNewValue Event

windowsforms-devexpress-dot-xtraeditors-dot-searchlookupedit-a2be0213.md

latest3.5 KB
Original Source

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.v25.2.dll

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

Declaration

csharp
public event AddNewValueEventHandler AddNewValue
vb
Public Event AddNewValue As AddNewValueEventHandler

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.

csharp
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;
        }
    }
}
vb
Private Sub searchLookUpEdit1_AddNewValue(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.AddNewValueEventArgs)
    ' Specifies/generates a unique identifier for a new record.
    Dim newRecordId As Integer = { 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 newRecordForm As 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 Then
            e.NewValue = newRecordId
            e.Cancel = False
        End If
    End Using
End Sub

See Also

ShowAddNewButton

ValueMember

SearchLookUpEdit Class

SearchLookUpEdit Members

DevExpress.XtraEditors Namespace