Skip to main content

DxComboBox<TData, TValue>.SelectedItemChanged Event

Fires when the ComboBox’s selected item is changed.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public EventCallback<TData> SelectedItemChanged { get; set; }

Parameters

Type Description
TData

The data item type.

Remarks

Handle the SelectedItemsChanged event to respond to item selection changes. This event fires in the following cases:

  • When users change item selection.
  • When Value property is changed in code. This also includes the first render.
<DxComboBox Data="@Cities"
            @bind-Value="CurrentCity"
            TextFieldName="@nameof(City.CityName)"
            SelectedItemChanged="@((City city) => SelectedItemChanged(city))">
</DxComboBox>

<p>@msg</p>

@code {
    List<City> Cities { get; set; } = CountryCity.Cities;
    City CurrentCity { get; set; } = CountryCity.Cities[4];
    string msg;

    void SelectedItemChanged(City city) {
        msg = "Selected item: " + city.CityName;
    }

    public class City {
        public int Id { get; set; }
        public string CityName { get; set; }

        public override bool Equals(object obj) {
            return obj is City city && string.Equals(city.CityName, CityName, StringComparison.OrdinalIgnoreCase) && city.Id == Id;
        }

        public override int GetHashCode() {
            return HashCode.Combine(Id, CityName);
        }
    }

    public static class CountryCity {
        private static readonly Lazy<List<City>> cities = new Lazy<List<City>>(() =>  {  
           return new List<City>() {
              new City() { Id = 0, CityName = "Washington" },
              new City() { Id = 1, CityName = "New York" },
              new City() { Id = 2, CityName = "Los Angeles" },
              new City() { Id = 3, CityName = "Berlin" },
              new City() { Id = 4, CityName = "Munich" },
              new City() { Id = 5, CityName = "Hamburg" },
              new City() { Id = 6, CityName = "Tokyo" },
              new City() { Id = 7, CityName = "Osaka" },
              new City() { Id = 8, CityName = "Yokohama" }
            };
        });
        public static List<City> Cities { get { return cities.Value; } }
    }
}

Combobox Selection changed

See Also