Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DxComboBox<TData, TValue>.SelectedDataItemChanged Event

Fires when the ComboBox’s selected item is changed.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
[Parameter]
public EventCallback<SelectedDataItemChangedEventArgs<TData>> SelectedDataItemChanged { get; set; }

#Event Data

The SelectedDataItemChanged event's data class is SelectedDataItemChangedEventArgs<TData>. The following properties provide information specific to this event:

Property Description
ChangeSource Identifies an action that causes selection change. Inherited from SelectionChangedEventArgs.
DataItem Returns the currently selected item.

#Remarks

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

  • When users change item selection.
  • When Value and Text properties are changed in code. This also includes the first render.

The SelectedDataItemChanged event allows you to use the following argument properties in a handler:

  • ChangeSource to identify an action that causes selection change.
  • DataItem to obtain information about the currently selected item.
Razor
<DxComboBox Data="@Cities"
            @bind-Value="CurrentCity"
            TextFieldName="@nameof(City.CityName)"
            SelectedDataItemChanged="(SelectedDataItemChangedEventArgs<City> args) =>
                                     OnSelectedCityChanged(args)" />

<p>@msg</p>

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

    void OnSelectedCityChanged(SelectedDataItemChangedEventArgs<City> args) {
        if (args.ChangeSource == SelectionChangeSource.ParameterChange)
            msg = "Selection changed in code. The selected item: " + args.DataItem.CityName;
        else
            msg = "Selection changed by a user action. The selected item: " + args.DataItem.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; } }
    }
}
See Also