function for deselected Item

Currently my SelectionChanged function do change a image if my Item is selected with the following code:

foreach (var item in PraeparatList.SelectedItems)
{
System.Reflection.PropertyInfo pi = item.GetType().GetProperty("PraeparatID");
int id = (int)(pi.GetValue(item, null));
var q = viewModel.PraeparatInfo.Where(X => X.PraeparatID == id).FirstOrDefault();
q.PraeparatCheck = "checked.png";
}

But how can i rechange the Image to unchecked.png if the item has changed to unselected?


So i was wondering if there exist a way to Get all UnselectedItems. This were great


3 Replies 1 reply marked as answer

SY Suthi Yuvaraj Syncfusion Team August 29, 2022 02:14 PM UTC

Hi Steven,


We have checked with the reported query “function for deselected Item” , SfListView allows you to get the added and removed items in the SelectionChanged Event. Please refer the below code snippet to get the items in the SelectionChanged event,


Code snippet:

listView.SelectionChanged += listView_SelectionChanged;

 

private void listView_SelectionChanged(object sender, Syncfusion.Maui.ListView.ItemSelectionChangedEventArgs e)

{

if (e.AddedItems.Count > 0)

{

    foreach (var item in listView.SelectedItems)

    {

        var it = item as BookInfo;

        it.Image = "selected.png";

    }

}

if (e.RemovedItems.Count > 0)

{

    var item = e.RemovedItems;

    foreach (var it in item)

    {

        var selectitem = it as BookInfo;

        selectitem.Image = "skyblue.png";

    }

 

}


Also Please refer the below UG documentation link for selectionchanged event:

UG Link: https://help.syncfusion.com/maui/listview/selection?cs-save-lang=1&cs-lang=csharp#show-checked-circle-on-selected-items


Please let us know if you need further assistance.


Regards,

Suthi Yuvaraj.


Marked as answer

ST Steven August 29, 2022 02:30 PM UTC

This was exact what i was looking for ... RemovedItems 


Thanks



SY Suthi Yuvaraj Syncfusion Team August 30, 2022 09:08 AM UTC

Hi Steven,


We are glad to know that your problem has been resolved. Please let us know if you need any other assistance. We will be happy to assist you.


Regards,

Suthi Yuvaraj.



Loader.
Up arrow icon