Unselect selected item

Hi!

I am using the ListBox component. Is it possible to deselect a selected item by clicking on the item again?

Thank you!

3 Replies 1 reply marked as answer

AS Aravinthan Seetharaman Syncfusion Team April 7, 2021 09:58 AM UTC

 
Thanks for contacting Syncfusion Support. 
 
We have checked your requirement. We can achieve your requirement by using selectItems method in ListBox change event handler. Please refer the below code snippet and sample. 
 
 
// Initialize the ListBox component. 
let listObj: ListBox = new ListBox({ 
  // Set the info to the dataSource property. 
  dataSource: (data as any).info, 
  selectionSettings: { mode: "Multiple" }, 
  change: onChange 
}); 
let element: Element[]; 
let item: string[] = []; 
function onChange(args: ListBoxChangeEventArgs): void { 
  if (element && args.elements.length == 1 && element[0] == args.elements[0]) { 
    for (var i = 0; i < args.items.length; i++) { 
      item[i] = args.value[i]; 
    } 
    listObj.selectItems(item, false); 
    element = null; 
  } else { 
    element = args.elements; 
  } 
} 
 
 
 
Could you please check whether the above details are fulfilling your requirement, and get back to us, if you need assistance on this. 
 
Regards, 
Aravinthan S

Marked as answer

KN Kulcsár Norbert April 7, 2021 11:35 AM UTC

Hi Aravinthan!


The provided solution is working fine, thank you!


AS Aravinthan Seetharaman Syncfusion Team April 7, 2021 01:06 PM UTC

Hi Kulcsár, 
 
Thanks for the update. 
 
We are happy to hear that your issue has been resolved. Please feel free to contact us if you need any further assistance on this. 
 
Regards, 
Aravinthan S 


Loader.
Up arrow icon