Chad
March 30, 2023, 8:43pm
1
I have a form with a RadzenDropDown with an object list bound to it.
The idea is a user can search that drop down to select a value (normal usage, works fine)
OR they can add a new object via a button.
When they click the add button, I create the new object and set the property of the main object to the Id of this new object, all is well functionally.
What I'd like to do it refresh the RadzenDropDown with the latest list (as it was plus the new object just created) and then select that new value so the user sees what they have selected (they 'selected' it by creating a new one).
Basically 're loading' the dropdown I think would do it, don't see a reload method like exists for a datagrid...
Any direction appreciated.
enchev
March 31, 2023, 4:37am
2
In Blazor this can be done with two way binding - i.e @bind-Value=someVariable. Every change no matter in the variable or in the component will be synced.
P4TTT0
January 11, 2024, 12:48pm
3
Hello! I tried that but that's not working for me, i have the next code:
private async void OnAddMatchPersonClick()
{
MatchPerson matchPerson = await DialogService.OpenAsync("Add MatchPerson", null);
if(matchPerson is not null)
{
this.radzenDropDown.Reset();
this.matchFaceTemplate.MatchPersonId = matchPerson.MatchPersonId;
}
}
And
<RadzenDropDown @ref="this.radzenDropDown" Data="@matchPeopleForMatchPersonId " TextProperty="Name" ValueProperty="MatchPersonId" AllowClear=true
Placeholder="Choose MatchPerson" style="display: block; width: 100%" @bind-Value=@matchFaceTemplate.MatchPersonId Name="MatchPersonId"/>
P4TTT0
January 11, 2024, 1:15pm
5
But that way I cant open the Dialog.
enchev
January 11, 2024, 1:25pm
6
You should use async Task.
P4TTT0
January 11, 2024, 1:44pm
7
Sorry for the insistence but is not working. I need to configure something on the RadzenDropDown component?
1 Like
Chad
January 11, 2024, 6:20pm
8
@P4TTT0
I want to help, but can't find the place where I did this, if I come across it, I'll let you know.
what is your current code? did you switch to async Task?
P4TTT0
January 12, 2024, 12:08pm
9
Hello @Chad thank you for your willingness to help!
Yes I switched to async Task, this is my current code:
<RadzenColumn Size="1" SizeSM="1" SizeMD="1">
<RadzenButton Style="width: 100%" ButtonStyle="ButtonStyle.Primary" Icon="add" Variant="Variant.Flat" Click="@OnAddMatchPersonClick" />
</RadzenColumn>
<RadzenColumn Size="8" SizeSM="8" SizeMD="8">
<RadzenDropDown @ref="this.radzenDropDown" Data="@matchPeopleForMatchPersonId" TextProperty="Name" ValueProperty="MatchPersonId" AllowClear=true
Placeholder="Choose MatchPerson" style="display: block; width: 100%" @bind-Value=@matchFaceTemplate.MatchPersonId Name="MatchPersonId"/>
</RadzenColumn>
code behind:
private async Task OnAddMatchPersonClick()
{
MatchPerson matchPerson = await DialogService.OpenAsync<AddMatchPerson>("Add MatchPerson", null);
if (matchPerson is not null)
{
this.radzenDropDown.Reset();
this.matchFaceTemplate.MatchPersonId = matchPerson.MatchPersonId;
}
}
The idea is that the user can add a person to the list and then have the RadzenDropDown automatically select it.
Something to note is that I had to perform the .resest() on the component because otherwise the values in the list would not be updated
Chad
January 12, 2024, 2:18pm
10
@P4TTT0 so you have it working now?
P4TTT0
January 12, 2024, 6:14pm
11
No :(, The new person it appears on the RadzenDropDown but it does not select automatically