JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › ListBox › Set the selected values/index programmatically as an embedded component › Reply To: Set the selected values/index programmatically as an embedded component
Thank you for the example. The example is working but unfortunately in my case it is not
and I can’t figured it out why the initial selection is not working:
Here is my code example:
I have the following parent component:
<h3>ParentComponent</h3>
<Button id=”openButton” OnClick=”OnClick”>Open/Close</Button>
<ChildComponent OpenDialog=”@opened” OnClosed=”OnClosed” >
</ChildComponent>
@code
{
private bool opened = false;
private void OnClick()
{
opened = !opened;
}
private void OnClosed()
{
opened = false;
}
}
And the child component is:
<h3>ChildComponent</h3>
<Window IsOpened=”@OpenDialog” Label=”Test” Modal=true HeaderButtons=”@headerButtons” OnClose=”Closed”>
<ListBox DataSource=”@myData” SelectedValues=”@selectedValues” Editable=true>
</ListBox>
</Window>
@code {
[Parameter]
public bool OpenDialog { get; set; } = false;
[Parameter]
public EventCallback OnClosed { get; set; }
private string[] myData = new string[] { “1”, “2”, “3” };
private string[] selectedValues = new string[] { “2”, “3” };
private string[] headerButtons = new string[] { “close” };
private async Task Closed(Event ev)
{
await OnClosed.InvokeAsync();
}
}