Skip to main content
All docs
V24.1

DxDropDownListEditorBase<TData, TValue>.KeyFieldNames Property

Specifies the names of data fields that contain key values. The combination of key values forms a unique identifier for a component item.

Namespace: DevExpress.Blazor.Base

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public IReadOnlyList<string> KeyFieldNames { get; set; }

Property Value

Type Description
IReadOnlyList<String>

The list of key field names.

Remarks

Note

The KeyFieldNames property was introduced in v24.1.6.

When the ComboBox/TagBox works with business objects, we recommend that you set the DevExpress.Blazor.Base.DxDropDownListEditorBase2.KeyFieldName orKeyFieldNames` property. The component uses the specified key fields to identify and compare data items.

Set the KeyFieldName/KeyFieldNames property in the following cases:

  • When you use the CustomData property to bind the component to data stored on a remote service and loaded through a Web API.
  • When you use the Data property to bind the component to a data collection (Data) that stores business objects (IEnumerable<CustomType>) and you specify a business object in the Value property.

If you do not specify key fields, the ComboBox/TagBox uses standard .NET value equality comparison to identify and compare data items. In this case, you should override object type’s Equals and GetHashCode methods to ensure correct identification of objects. However, the best way to identify objects is to use KeyFieldName and KeyFieldNames properties.

The following code snippet specifies the OrderId and ProductId field values as keys for the OrderDetail data objects.

@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable

<DxComboBox Data="DataSource"
            @bind-Value="@Value"
            KeyFieldNames="KeyFieldNames">
    <Columns>
        <DxListEditorColumn FieldName="OrderId" Caption="Order ID" />
        <DxListEditorColumn FieldName="ProductId" Caption="Product ID" />
        <DxListEditorColumn FieldName="UnitPrice" />
        <DxListEditorColumn FieldName="Quantity" />
        <DxListEditorColumn FieldName="Discount" />
    </Columns>
</DxComboBox>

@code {
    IEnumerable<object> DataSource { get; set; }
    NorthwindContext Northwind { get; set; }
    OrderDetail Value { get; set; }

    protected override void OnInitialized() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        DataSource = Northwind.OrderDetails
            .ToList();
    }

    IReadOnlyList<string> KeyFieldNames = new [] {
        "OrderId",
        "ProductId",
    };

    public void Dispose() {
        Northwind?.Dispose();
    }
}

Implements

DevExpress.Blazor.IListEditorBase<TData, TValue>.KeyFieldNames
See Also