Select Event is not fired

Hi there, 
Using the SfListBox Component is not being fired.

@using Syncfusion.Blazor.DropDowns
<div class="col-lg-12 control-section">
    <div id="listbox-control">
        <h4>Select your favorite car:</h4>
        <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" Select="@Select" />
        </SfListBox>
    </div>
</div>
@code{

    private void OnValueChangeCallback()
    { 
    }

    private void Select()
    { 
    }
    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; }
    }
}

3 Replies 1 reply marked as answer

GK Gayathri KarunaiAnandam Syncfusion Team April 8, 2021 10:41 AM UTC

Hi Adriana, 

We have checked your reported query. We have deprecated the Select event of Listbox. We suggest that the ValueChange event triggers when select/unselect the Listbox item. Please check the below code snippet and links. 


Code snippet: 
 
        <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 get back to us, if you need further assistance. 

Regards, 
Gayathri K 


Marked as answer

RR Richard Rooks March 13, 2023 03:20 PM UTC

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.



YA YuvanShankar Arunagiri Syncfusion Team March 14, 2023 08:49 AM UTC

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


Attachment: BlazorApp1_755b034c.zip

Loader.
Up arrow icon