|
<SfListBox Value="@Value" DataSource="@Data" TItem="DataValues" TValue="string[]">
<ListBoxSelectionSettings ShowCheckbox="true"></ListBoxSelectionSettings>
<ListBoxFieldSettings Text="Text" Value="Id"></ListBoxFieldSettings>
<ListBoxEvents TValue="string[]" TItem="DataValues" ValueChange="@OnValueChangeCallback" />
</SfListBox>
@code{
private void OnValueChangeCallback()
{
// Your code here
}
private string[] Value = new string[] { "List-01" };
private List<DataValues> Data = new List<DataValues>
{
new DataValues{ Text = "Hennessey Venom", Id = "List-01" },
new DataValues{ Text = "Bugatti Chiron", Id = "List-02" },
new DataValues{ Text = "Bugatti Veyron Super Sport", Id = "List-03" },
new DataValues{ Text = "SSC Ultimate Aero", Id = "List-04" },
new DataValues{ Text = "Koenigsegg CCR", Id = "List-05" },
new DataValues{ Text = "McLaren F1", Id = "List-06" },
new DataValues{ Text = "Aston Martin One- 77", Id = "List-07" },
new DataValues{ Text = "Jaguar XJ220", Id = "List-08" },
new DataValues{ Text = "McLaren P1", Id = "List-09" },
new DataValues{ Text = "Ferrari LaFerrari", Id = "List-10" }
};
public class DataValues
{
public string Text { get; set; }
public string Id { get; set; }
}
} |
Please explain to me how this code example gives you the selected item in the listbox that the user clicked on? I downloaded the example zip file and it does absolutely nothing to give the developer the selected item in the list. The VALUE array never changes. It always has the initial value no matter what the user clicks on.
Hi Richard,
We have checked your reported query and using the below code line, we can get the selected items in ValueChange event of ListBox component.
|
private void OnValueChangeCallback(ListBoxChangeEventArgs<string[], DataValues> args) { var selectedItem = args.Value; } |
And Value property of ListBox hold initial value alone, if you it dynamically then, we need to set as shown below.
|
<SfListBox @bind-Value="@Value" DataSource="@Data" TItem="DataValues" TValue="string[]"> |
Check with attached sample and get back to us if you need any further assistance on this.
Regards,
YuvanShankar A