RadzenDataGrid - Focusing on numeric field when entering edit mode

I am trying to set the focus of a specific row field when I click on a different field to enter edit mode.

For instance,
In my tag I have a read only numeric field and when I click on that field I go into row edit mode. Then I want to focus on the field that is in the EditTemplate area. Looking at the code below you will see the read only RadzenNumeric in the Template tag. @onkeyup triggers the EditRow() function. Once the EditTemplate is rendered I want to focus on the RadzenNumeric field in the EditTemplate tag. I have tried all of the examples I could find but could not get it to focus.

I am referencing the field with ..
public RadzenNumeric<decimal?> FocusField { get; set; } = default!;

<Template Context="ratesItem">
   <RadzenNumeric @bind-Value="ratesItem.New_Rate" @onkeyup="@(e => KeyPressed(e,ratesItem))" Step="0.01" />
</Template>
<EditTemplate Context="ratesItem">
   <RadzenNumeric @bind-Value="ratesItem.New_Rate" id="New_Rate_Focus" @onfocusout="@(e => CheckValidation(ratesItem))" Step="0.01" Name="New_Rate" />
</EditTemplate>

Hi @DonnieRCrump,

To focus a Radzen Numeric component from code you should invoke its FocusAsync method.

I have tried that.

I used a simple @onmouseover="FunctionCall(FocusField)" and then used myFocusField.FocusAsync();

I even tried to do a Task.Delay(2000) and then the FocusAsync() call. The field still does not focus. The debugging in Visual Studio show the delay and the call but the field still doesn't focus.

Is there maybe a complete piece of code that shows the full function call with the FocusAsync()?

Hi, was this ever resolved? It seems to me that FocusAsync doesn't work on numeric fields...

Hi @SolutionJ,

There are no known issues with the FocusAsync method of RadzenNumeric. After all it calls the built-in Blazor method of the internal input element.

There are several posts about it in the forum, @korchev, some with no answers.
After several hours of searching, I did just find in the github code for the RadzenNumeric object that because of its nature you can't reference it with the fieldref.Element.FocusAsync() construct, instead you have to reference it with fieldref.FocusAsync().

Cheers
Reg

My response in this thread linked to that precise method. However the line number has changed with time. I have updated the link.

1 Like