Skip to main content
All docs
V24.1

DxDropDownListEditorBase<TData, TValue>.KeyFieldName Property

Specifies the field name that contains unique identifiers for component items.

Namespace: DevExpress.Blazor.Base

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

[DefaultValue("")]
[Parameter]
public string KeyFieldName { get; set; }

Property Value

Type Default Description
String String.Empty

The key field’s name.

Remarks

Note

The KeyFieldName property was introduced in v24.1.6.

When the ComboBox/TagBox works with business objects, we recommend that you set the KeyFieldName property. If your data objects have a compound key, use the KeyFieldNames property instead. The component uses 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 specifies the ProductId field as a key.

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

<DxComboBox Data="DataSource"
           @bind-Value="@Value"
           KeyFieldName="ProductId">
    <Columns>
        <DxListEditorColumn FieldName="ProductName" />
        <DxListEditorColumn FieldName="UnitPrice" />
        <DxListEditorColumn FieldName="QuantityPerUnit" />
        <DxListEditorColumn FieldName="UnitsInStock" />
    </Columns>
</DxComboBox>

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

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

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

Implements

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