Reputation: 685
I have a longlistmultiselector in which i need to remove an element. I am able to remove the element from the itemsource of it, but the same is not reflected in the UI. In UI screen there is no change.
The following is the code for removing item from lonlistmultiselector(onboardList) :
var updatedReviewList = onboardList.ItemsSource;
MessageBoxResult result = MessageBox.Show(Constants.DELETE_MSG, Constants.DELETE_MSG, MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
if (reqDetails != null)
{
for (var index = 0; index < onboardList.ItemsSource.Count; index++ )
// foreach (var item in onboardList.ItemsSource)
{
var item = onboardList.ItemsSource[index];
if (onboardList.SelectedItems.Contains(item))
{
//this.onboardList.ItemsSource.Remove(item);
updatedReviewList.Remove(item);
}
}
this.onboardList.ItemsSource = updatedReviewList;
}
Any idea what I might be missing? Thanks in advance
Upvotes: 0
Views: 47
Reputation: 191
Do this.. It should work.
this.onboardList.ItemsSource = null;
this.onboardList.ItemsSource = updatedReviewList;
It's better if you use an ObservableCollection of objects that implements INotifyPropertyChanged. This will allow two way binding of data. If something gets removed from your itemsource, it will reflect in the UI and if something is removed from the UI, it will automatically delete that entry from your ObservableCollection
More info on that here:-
http://msdn.microsoft.com/en-us/library/windows/apps/cc278072%28v=vs.105%29.aspx
Upvotes: 3