Unplanned
Last Updated: 23 Mar 2026 12:12 by S
S
Created on: 23 Mar 2026 12:12
Category: ComboBox
Type: Bug Report
1
ComboBox Value does not display if virtual scrolling ValueMapper completes before render

If the ComboBox Value is set during initialization and the ValueMapper executes too fast and before the component has rendered, its Value doesn't show.

The problem also occurs in the MultiColumnComboBox.

Possible workarounds:

  • Set the component Value a bit later.
  • Delay the ValueMapper execution until OnAfterRenderAsync fires.
  • Rebind() the ComboBox in OnAfterRenderAsync. This will fire OnRead again.
  • Render the ComboBox conditionally in the first OnAfterRenderAsync call.

To reproduce:

@using Telerik.DataSource
@using Telerik.DataSource.Extensions

<p>ComboBox Value: @ComboBoxValue</p>

<TelerikComboBox ItemHeight="30"
                 OnRead="@OnComboBoxRead"
                 PageSize="20"
                 ScrollMode="@DropDownScrollMode.Virtual"
                 TItem="@ListItem"
                 TValue="@(int?)"
                 @bind-Value="@ComboBoxValue"
                 ValueMapper="@ComboBoxValueMapper"
                 Width="240px" />

@code {
    private List<ListItem>? ComboBoxData { get; set; }

    private int? ComboBoxValue { get; set; } = 3;

    private async Task OnComboBoxRead(ReadEventArgs args)
    {
        DataSourceResult result = await ComboBoxData.ToDataSourceResultAsync(args.Request);

        args.Data = result.Data;
        args.Total = result.Total;
    }

    private async Task<ListItem?> ComboBoxValueMapper(int? selectValue)
    {
        // Triggers the bug
        await Task.Yield();

        ListItem? result = ComboBoxData?.FirstOrDefault(x => selectValue == x.Value);

        return result;
    }

    protected override void OnInitialized()
    {
        ComboBoxData = Enumerable
            .Range(1, 1234)
            .Select(x => new ListItem()
                {
                    Value = x,
                    Text = $"Item {x}"
                })
            .ToList();
    }

    public class ListItem
    {
        public int Value { get; set; }
        public string Text { get; set; } = string.Empty;
    }
}

0 comments