Skip to main content

DxComboBox<TData, TValue>.Data Property

Specifies a strongly typed collection that supplies ComboBox data.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.1.dll


public IEnumerable<TData> Data { get; set; }

Property Value

Type Description

A data collection.


Use the Data property to bind the ComboBox to a strongly typed collection or enumeration. Initialize this object in the OnInitialized lifecycle method or before this method is invoked.

Bind to a standard-type collection

The following sample demonstrates how to bind the ComboBox to an array of string values:

 <DxComboBox Data="@(new string[] { "London", "Berlin", "Paris" })"></DxComboBox>

ComboBox Sample Data

You can also set the Data property to the name of a variable that stores the data collection.

<DxComboBox Data="@Cities" @bind-Value="@Value"></DxComboBox>

@code {
  IEnumerable<string> Cities = new List<string>() {

  string Value { get; set; }

Bind to a custom-type collection

If you bind the ComboBox to a data collection that stores custom objects (IEnumerable<CustomType>), override the object’s Equals method and set the TextFieldName property. This property specifies the custom object’s field name that returns strings for the ComboBox’s drop-down window.

@using BlazorApp.Data

<DxComboBox Data="@Staff.DataSource"

@code {
  Person SelectedPerson { get; set; } = Staff.DataSource[0];

ComboBox CustomObject

Otherwise, the ComboBox’s items are populated with CustomType.ToString() values.

Use the DataAsync property instead of the Data property if a strongly typed collection is loaded asynchronously (for instance, from an HTTP request). Use the CustomData property if your data is stored on a remote service and is loaded through a Web API.

Bind to an enumeration

To bind the ComboBox to an enumeration, create a wrapper class that obtains Enum values and passes them to the component’s Data property. For instance, you want to show the following enumeration items in the ComboBox:

using System.ComponentModel.DataAnnotations;

public enum EducationType {
    [Display(Name = "Not Stated")]
    NoInfo = 0,
    [Display(Name = "High school")]
    School = 1,
    [Display(Name = "College")]
    College = 2,
    [Display(Name = "University Degree")]
    UniversityDegree = 3,
    [Display(Name = "PhD")]
    PhD = 4

To do this, declare a wrapper class with two properties:

public class EducationDegree {
    // Specifies an enumeration value
    public EducationType Value { get; set; }
    // Specifies text to display in the ComboBox
    public string DisplayName { get; set; }

Create a generic extension method that gets the Display attribute’s Name value from the enumeration’s item.

using System;
using System.Linq;
using System.Reflection;

public static class Extensions {
    public static TAttribute GetAttribute<TAttribute>(this Enum enumValue)
            where TAttribute : Attribute {
        return enumValue.GetType()

Add the ComboBox to a project and override the OnInitialized lifecycle method that creates a match between integer and string values of the enumeration’s item.

@using System.ComponentModel.DataAnnotations;
@using Education.Data

<DxComboBox Data="EducationDegrees" 

@code {
    public List<EducationDegree> EducationDegrees { get; set; } = new List<EducationDegree>();
    int Value { get; set; } = 0;

    protected override void OnInitialized() {
        EducationDegrees = Enum.GetValues(typeof(EducationType))
            .Select(t => new EducationDegree()
                Value = t,
                DisplayName = t.GetAttribute<DisplayAttribute>().Name

Combo Box - Enum example

See Also