Skip to main content
All docs
V25.1
  • DxListEditorBase<TData, TValue>.KeyFieldName Property

    Specifies the key field used for data item identification when the list editor uses a business object as a value.

    Namespace: DevExpress.Blazor.Base

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

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

    Property Value

    Type Default Description
    String null

    The key field’s name.

    Remarks

    Note

    The KeyFieldName 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 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 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 specifies the ProductId field as a key:

    @using Microsoft.EntityFrameworkCore
    @inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
    @implements IDisposable
    
    <DxListBox Data="DataSource"
               @bind-Values="@Values"
               KeyFieldName="ProductId">
        <Columns>
            <DxListEditorColumn FieldName="ProductName" />
            <DxListEditorColumn FieldName="UnitPrice" />
            <DxListEditorColumn FieldName="QuantityPerUnit" />
            <DxListEditorColumn FieldName="UnitsInStock" />
        </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.Products
                .ToList();
        }
    
        public void Dispose() {
            Northwind?.Dispose();
        }
    }
    

    Implements

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