DxDropDownBox.ValueChanging Event
Fires when the editor value is being modified. Use this event to validate or cancel the new value.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v25.2.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public Action<ParameterValueChangingEventArgs<object>> ValueChanging { get; set; }
Event Data
The ValueChanging event's data class is ParameterValueChangingEventArgs<Object>. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| NewValue | Gets or sets the new value being assigned to the parameter. |
| OldValue | Gets the current parameter value. |
Remarks
The ValueChanging event fires before a new value is applied to the component (before the ValueChanged event). You can use this event to validate or cancel the new value.
The following code prevents restricted item selection. If a user tries to select an item that is marked as restricted, the DropDownBox’s value remains unchanged.
<DxDropDownBox Data="@Categories"
@bind-Value="@SelectedCategory"
TextFieldName="@nameof(Category.Name)"
ValueChanging="@OnValueChanging">
<DropDownTemplate>
<DxListBox Data="@Categories"
TextFieldName="@nameof(Category.Name)"
@bind-Value="@SelectedCategory" />
</DropDownTemplate>
</DxDropDownBox>
@code {
Category SelectedCategory { get; set; }
IEnumerable<Category> Categories { get; set; }
protected override void OnInitialized() {
Categories = new List<Category> {
new Category { Name = "Regular Items", IsRestricted = false },
new Category { Name = "Premium Items", IsRestricted = true },
new Category { Name = "Standard Items", IsRestricted = false }
};
SelectedCategory = Categories.First();
}
void OnValueChanging(ParameterValueChangingEventArgs<object> e) {
if (e.NewValue is Category category && category.IsRestricted) {
e.NewValue = e.OldValue;
}
}
public class Category {
public string Name { get; set; }
public bool IsRestricted { get; set; }
}
}