How to pre-select an item in the ListView?

Is there a way to pre-select an item in the list so that also it will be highlighted just like when you manually select an item using your mouse.

3 Replies 1 reply marked as answer

SP Sowmiya Padmanaban Syncfusion Team July 15, 2020 12:41 PM UTC

Hi J,  
 
Greetings from Syncfusion support. 
 
We have checked your requirement with ListView component. ActionComplete event will trigger when every list action complete. In that event, we can pre select any list item using SelectItem method of ListView component . 
 
Refer the below code snippet. 
 
  <SfListView ID="listview" DataSource="@Data" @ref="@list" Height="200px"> 
        <ListViewEvents TValue="DataModel" OnActionComplete="complete"></ListViewEvents> 
        <ListViewFieldSettings Id="Id" Text="Text" IsChecked="isChecked"></ListViewFieldSettings> 
    </SfListView> 
  public void complete(Object args) 
    { 
        // Select the listview items using selectItem method. 
        this.list.SelectItem(new DataModel { Id = "list-02" }); 
    } 
 
Refer the below screenshot. 
 
 
Refer the below sample link: 
 
To know more about the ListView component, refer the below links. 
 
 
 
 
Please let us know, if you need an further assistance. 
 
Regards,  
Sowmiya.P 



SA Simon Arnold replied to Sowmiya Padmanaban August 5, 2021 03:00 PM UTC

I seem to be getting a message saying that this method is deprecated and will no longer be used, if this is the case what is the correct way of selecting the default item ?




KR Keerthana Rajendran Syncfusion Team August 6, 2021 05:40 AM UTC

Hi Simon, 
 
Sorry for the inconvenience.  
 
ListView is used for displaying the list items and we will not maintain the pre-selection in ListView component. When streamline this component to Blazor standard in 2020 Volume 3 release(18.3.35), we have deprecated all the selection related methods(GetSelectedItems, selectItem and SelectMultipleItems).  Refer to the below release notes.   
    
     
We can maintain the selection only by enabling the ShowCheckBox property of ListView component. We can check an item programmatically using checkItem method of ListView. This is the default behavior of ListView component.     
    
If you want to select the list items without using checkbox property, we suggest you to use the ListBox component to achieve your requirement which is similar to ListView component.      
 
Refer to the following links for more details on ListBox component.  
 
     
 
  
Please let us know if you need further assistance.  
  
Regards,  
Keerthana R.  


Marked as answer
Loader.
Up arrow icon