I have a listview which receives information from a HashSet, but when I delete one item of the HashSet, my listview is not updated.
And my listview doesn't have a method of refresh, don't know why. Here is my code:
private void deleteActivityFromAlumn(String activityName, String nif)
{
Alumn alumnDelete = Alumn.findAlumnByNIF(nif);
Activity activityDelete = Activity.getActivityByName(activityName);
Debug.WriteLine(alumnDelete.Name + activityDelete.Name);
alumnDelete.activities.Remove(activityDelete);
activityDelete.Alumns.Remove(alumnDelete);
listActivities.ItemsSource = alumnDelete.activities;
}
And the item is deleted in a right way because if I go search for the object again, it is removed from the listView, but I believe that its supposed to be updated when you refresh the ItemsSource.
To make sure that control with bound items changes when those items change you have to
ObservableCollection<T>
instead of HashSet<T>
HashSet<T>
gives you.listActivities.ItemsSource = null;
listActivities.ItemsSource = alumnDelete.activities
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.