I'm trying to follow your dual listbox drag and drop demo. Here is a relevant code:
Here is the exercise class:
The problem I am having is that when I drag and drop or move items from the left list into the right list, the underlying datasource is not updated. And even when I use the reference to the the list boxes themselves, the datasource shows as empty. How do I get at what is currently in a ListBox?
Hi Christopher,
Query: the datasource shows as empty. How do I get at what is currently in a ListBox?
To get updated data source from the listbox, kindly use the GetDataList method of listbox. Please refer the below code snippet and attached sample code.
private void GetData() { var list1_updated_data = _newRuleExercisesListBox.GetDataList(); var list2_updated_data = _newRuleExercisesSelectedListBox.GetDataList(); } |
Please get back to us if you need any further assistance on this.
Regards,
YuvanShankar A
Why cannot we just bind the value of the DataList using @bind-Value ? When doing so, the Value ist always null.
Hi Sven,
We have checked the reported query, and while binding `@bind-Value` to the ListBox, you can obtain the currently selected value. Please refer to the code snippets, sample, and video demonstration below.
<SfButton CssClass="e-primary" @onclick="Click">Get Value</SfButton> <div class="col-lg-12 control-section"> <div id="listbox-control"> <h4>Select your favorite car:</h4> <SfListBox @ref="ListBoxObj" AllowDragAndDrop="true" @bind-Value=@value DataSource="@vehicleData" TValue="string[]" TItem="ListItem"> <ListBoxFieldSettings Text="Text" Value="Text"></ListBoxFieldSettings> </SfListBox> </div> </div> @code { SfListBox<string[], ListItem> ListBoxObj; private string[] value = new string[] { "Hennessey Venom" }; private List<ListItem> vehicleData = new List<ListItem> { new ListItem { Text = "Hennessey Venom", Id = "List-01" }, new ListItem { Text = "Bugatti Chiron", Id = "List-02" }, new ListItem { Text = "Bugatti Veyron Super Sport", Id = "List-03" }, }; public class ListItem { public string Text { get; set; } public string Id { get; set; } } private void Click() { var currentSelectedValue= value; } } |
However, to obtain updated all data from the listbox, please use the GetDataList method of the listbox.
Please let us know if you need any further assistance on this.
KeerthiKaran K V