Allows a new value entered into the edit box, to be added to the items source.
public event ProcessNewValueEventHandler ProcessNewValue
Public Event ProcessNewValue As ProcessNewValueEventHandler
The ProcessNewValue event's data class is ProcessNewValueEventArgs. The following properties provide information specific to this event:
|DisplayText||Gets the text entered by an end-user within the editor’s edit box.|
|Handled||Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.|
|OriginalSource||Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.|
|PostponedValidation||Gets or sets whether to postpone edit value validation.|
|RoutedEvent||Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.|
|Source||Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.|
The event data class exposes the following methods:
|InvokeEventHandler(Delegate, Object)||When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.|
|OnSetSource(Object)||When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.|
If the editor cannot find an item that matches the text entered by an end-user within the edit box (ProcessNewValueEventArgs.DisplayText), the ProcessNewValue event occurs. Handle this event to manually validate a new value, and if required, add the corresponding record to a data source.
The ProcessNewValue event is raised after a new value has been validated, allowing you to add this value to the items source. By default, the validation occurs while typing within the editor’s text box (see BaseEdit.ValidateOnTextInput). As a result, the ProcessNewValue event is fired each time a user presses a keyboard key.
The ProcessNewValue event occurs if an end-user presses the Enter key (the BaseEdit.ValidateOnEnterKeyPressed property should be set to true) or moves focus to another control.
If you add a new record, set the event parameter’s Handled property to true.
If you want to show a floating container allowing an end-user to specify other values for a new record, set the event parameter’s ProcessNewValueEventArgs.PostponedValidation property to true. In this instance, a new value will be validated after a floating container is closed.
This example shows how to manually initialize a new value and add it to a data source.
Update: Starting with version 13.1 of DevExpress controls, you can use the DevExpress MVVM Framework to accomplish this task. It is necessary to create a command in the view model (for instance, the ShowProductFormCommand command) and bind it with the LookUpEditBase.ProcessNewValue event via the trigger. This would allow you to display the dialog (UserControl1.xaml file) for editing new source items in the LookUpEdit control when this even is raised. Then, you can implement custom logic in the OnShowProductFormCommandExecute (ProductList.cs file) method to process values in this dialog. Please review our blogs to find additional information about DevExpress MVVM Framework:
- Getting Started with DevExpress MVVM Framework. Commands and View Models.
- DevExpress MVVM Framework. Introduction to Services, DXMessageBoxService and DialogService.
- DevExpress MVVM Framework. Interaction of ViewModels. IDocumentManagerService.
<Application x:Class="HowToCreateLookUpEdit.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:HowToCreateLookUpEdit" xmlns:viewmodel="clr-namespace:HowToCreateLookUpEdit.ViewModel" StartupUri="MainWindow.xaml"> <Application.Resources> <viewmodel:StringToIntConverter x:Key="converter" /> </Application.Resources> </Application>