Back to Devexpress

DxComboBox<TData, TValue>.ValueChanging Event

blazor-devexpress-dot-blazor-dot-dxcombobox-2-d576c19c.md

latest2.6 KB
Original Source

DxComboBox<TData, TValue>.ValueChanging Event

Fires when the ComboBox’s selected value is being modified. Use this event to validate/cancel item selection.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
[Parameter]
public Action<ParameterValueChangingEventArgs<TValue>> ValueChanging { get; set; }

Event Data

The ValueChanging event's data class is ParameterValueChangingEventArgs<TValue>. The following properties provide information specific to this event:

PropertyDescription
NewValueGets or sets the new value being assigned to the parameter.
OldValueGets 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/cancel item selection.

The following code prevents selection of unavailable items. If a user tries to select an item that is marked as unavailable, the ComboBox’s value remains unchanged.

razor
<DxComboBox Data="@Products"
            @bind-Value="@SelectedProduct"
            ValueChanging="@OnValueChanging"
            TextFieldName="@nameof(Product.Name)" />

@code {
    Product SelectedProduct { get; set; }
    IEnumerable<Product> Products { get; set; }

    protected override void OnInitialized() {
        Products = new List<Product> {
            new Product { Name = "Product 1", IsAvailable = true },
            new Product { Name = "Product 2", IsAvailable = false },
            new Product { Name = "Product 3", IsAvailable = true }
        };
        SelectedProduct = Products.First();
    }

    void OnValueChanging(ParameterValueChangingEventArgs<Product> e) {
        if (e.NewValue != null && !e.NewValue.IsAvailable) {
            e.NewValue = e.OldValue;
        }
    }

    public class Product {
        public string Name { get; set; }
        public bool IsAvailable { get; set; }
    }
}

See Also

DxComboBox<TData, TValue> Class

DxComboBox<TData, TValue> Members

DevExpress.Blazor Namespace