RadzenDropdown keypress crashes if text property is not a string #1563

Open
opened 2026-01-29 17:55:27 +00:00 by claunia · 0 comments
Owner

Originally created by @cohenjw on GitHub (Jan 8, 2025).

Describe the bug
When a key is pressed in an expanded dropdown, the default HandleKeyPress behaviour in DropDownBase will use one of Radzen's QueryableExtensions to attempt to find items where the text property starts with the key pressed. Radzen doesn't automatically parse the property to a string unfortunately, therefore this results in a crash if the text property is an integer or any similar string parsable struct.

If my workaround in the next section is the expected approach and this is deemed not a bug, feel free to close. Thanks.

To Reproduce
The following code snippet reproduces the problem. Expand the dropdown and press any key, as it'll then attempt to query the items using StringFilterOperator.StartsWith:

<RadzenDropDown TValue="Model" Data=@_items TextProperty="@nameof(Model.ReferenceNo)" />

@code
{
	private List<Model> _items = new()
        {
		new() { ReferenceNo = 1 },
		new() { ReferenceNo = 2 }
	};

	public class Model
         {
		public int ReferenceNo { get; set; }
		
                // Workaround, use this as TextProperty instead.
                public string ReferenceNoString => ReferenceNo.ToString();
	}
}

Expected behavior
I would expect that if Radzen's query extensions perform string querying, that it always tries to ToString the property to ensure maximum compatibility. If that still fails, then that's on the user for providing a property that cannot be cast to a string.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Chrome
  • Version: 131.0.6778.205

Additional context
Radzen version 5.7.2

Originally created by @cohenjw on GitHub (Jan 8, 2025). **Describe the bug** When a key is pressed in an expanded dropdown, the default [HandleKeyPress behaviour in DropDownBase](https://github.com/radzenhq/radzen-blazor/blob/master/Radzen.Blazor/DropDownBase.cs#L622) will use one of Radzen's [QueryableExtensions](https://github.com/radzenhq/radzen-blazor/blob/c61d453de45e545b5d97faa6fb55fde555bcbe78/Radzen.Blazor/QueryableExtension.cs#L1267) to attempt to find items where the text property starts with the key pressed. Radzen doesn't automatically parse the property to a string unfortunately, therefore this results in a crash if the text property is an integer or any similar string parsable struct. If my workaround in the next section is the _expected_ approach and this is deemed not a bug, feel free to close. Thanks. **To Reproduce** The following code snippet reproduces the problem. Expand the dropdown and press any key, as it'll then attempt to query the items using `StringFilterOperator.StartsWith`: ```cs <RadzenDropDown TValue="Model" Data=@_items TextProperty="@nameof(Model.ReferenceNo)" /> @code { private List<Model> _items = new() { new() { ReferenceNo = 1 }, new() { ReferenceNo = 2 } }; public class Model { public int ReferenceNo { get; set; } // Workaround, use this as TextProperty instead. public string ReferenceNoString => ReferenceNo.ToString(); } } ``` **Expected behavior** I would expect that if Radzen's query extensions perform string querying, that it always tries to ToString the property to ensure maximum compatibility. If that still fails, then that's on the user for providing a property that cannot be cast to a string. **Screenshots** If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - OS: Windows 11 - Browser: Chrome - Version: 131.0.6778.205 **Additional context** Radzen version 5.7.2
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1563