DxDataGridComboBoxColumn<T>.Data Property

Specifies a strongly typed collection that supplies column data.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v21.1.dll

Declaration

[Parameter]
public IEnumerable<T> Data { get; set; }

Property Value

Type Description
IEnumerable<T>

A data source.

Remarks

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

@if (DataSource == null) {
    <div>Loading...</div>
} else {
<DxDataGrid Data="@DataSource">
    @*...*@
    <DxDataGridComboBoxColumn Field="@nameof(WeatherForecast.CloudCover)" Caption="Cloud Cover"
                              Data="@CloudCover" TextAlignment="DataGridTextAlign.Left" />
</DxDataGrid>
}

@code {
    IEnumerable<WeatherForecast> DataSource;

    public class WeatherForecast {
        // ...
        public string CloudCover { get; set; }

        public override bool Equals(object obj) {
            if (obj is WeatherForecast)
                return this.ID == ((WeatherForecast)obj).ID;
            return base.Equals(obj);
        }
    }

    public string[] CloudCover = new[] {
        "Sunny", "Partly cloudy", "Cloudy", "Storm"
    };

    protected override void OnInitialized() {
        DataSource = GetForecast();
    }

    public IEnumerable<WeatherForecast> GetForecast() {
        var rng = new Random();
        DateTime startDate = DateTime.Now;
        for (var i = 1; i < 15; i++) {
            yield return new WeatherForecast { Date = startDate.AddDays(i), 
                                               TemperatureC = rng.Next(-15, 20),
                                               CloudCover = CloudCover[rng.Next(0, CloudCover.Length)] };
        }
    }
}

Run Demo: Data Grid - Column Types

If you bind the ComboBox column 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 to be shown in the column’s drop-down window.

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.

See Also