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

DxListEditorBase<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.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
[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 a list editor (ComboBox, List Box, TagBox) works with business objects, we recommend that you set the DevExpress.Blazor.Base.DxListEditorBase2.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 editor to data stored on a remote service and loaded through a Web API.
  • When you use the Data property to bind the editor 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 list editor 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

<DxListBox Data="DataSource"
           @bind-Values="@Values"
           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>
</DxListBox>

@code {
    IEnumerable<object> DataSource { get; set; }
    NorthwindContext Northwind { get; set; }\
    IEnumerable<Order> Values { 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