We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SfListView Not Refreshed after Deletion or Update with Swiping

Hi, 

I am using swiping to delete an item, it is succesfully deleted via API request. 

However, I couldn't accomplish to refresh the corresponding listview after dropped item. 

And moreover, I need to update another listview in the previous page which I jumped into here with (financialId). 

I am using MVVM approach and asking for your support, thanks in advance.


private async void DeleteButtonTapped(object obj)
        {
            var itemData = obj as ExpenseDetail;

            try
            {
                TurnaManager turna = new TurnaManager();

                TurnaResponse response = await turna.DeleteExpenseDetail(itemData.ID);

                if (response.Level == "INFO")
                {
                    await Application.Current.MainPage.DisplayAlert("Bilgi", response.Message, "OK");
                    SfListExpense.ResetSwipe();
                    SfListExpense.RefreshView();
                }
                else
                {
                    await Application.Current.MainPage.DisplayAlert("Bilgi", response.Message + " " + response.Exception, "OK");
                }
            }
            catch (Exception ex)
            {
                
            }
        }

Attachment: SfList_Refresh_MVVM_2ea3a65d.zip

9 Replies

SR Sangeetha Raju Syncfusion Team September 4, 2019 12:29 PM UTC

Hi Murat, 
 
We would like to let you know that we are not clear with your requirement. Can you please share the snapshot of the issue facing while refreshing the item after dropping. Also, please share the details of your requirement to be achieved in the another ListView of previous page. It will help us to analyze your query better and provide your appropriate solution at our end. 
 
Regards, 
Sangeetha Raju. 



MU Murat September 10, 2019 08:37 PM UTC

Hi Raju, 

I had added relavant files (zip) in my thread before. Briefly I need a sample meeting requirements below; 

- An item of SfList is deleted or updated via swiping 
- After completed delete or update, list should be refreshed with existing/updated items (reflection from update/delete) 
- Using MVVM pattern (ViewModel.cs) is crutial 

Thanks in advance, looking forward to your precise help. 


GP Gnana Priya Namasivayam Syncfusion Team September 11, 2019 11:55 AM UTC

Hi Murat, 

We would like to inform that you need not call RefreshView method to update the Listview’s ItemsSource collection because listview will automatically update the collection once operations like Add, Remove, RemoveAt, Update is performed.  We have attached the sample for your reference which updates the collection after listview item deleted via swipe, please find the sample from below. 


Can you please check with the above sample whether your getting same issue in our sample also. Meanwhile, please ensure whether you have binded  the same collection(in which you delete) in ItemsSource of ListView. If issue still reproduced, can you please share video of your issue you are facing so that we could understand your query better and provide you appropriate solution. 

Regards, 
Gnana Priya N 



MU Murat September 17, 2019 12:45 PM UTC

Hi Gnana, 

Your sample is working properly. When I have implemented in my app code as you did, it worked as well. Trick point is you are removing swiped item from collection with  this.ContactsInfo.Remove(swipedItem); statement. Is it best practice? 

However, what about if I update an item by swiping/editing on another page or add an item on another page? 
The exact issue is that I need a refreshing SfListView after successful CUD operations. 


SR Sangeetha Raju Syncfusion Team September 18, 2019 02:10 PM UTC

Hi Murat, 
 
We can understand that you are using two ListView in two different pages and you are trying to delete/update through swipe in one page and expect the changes to be reflected in ListView available in another page. This can be done by changing the underlying data collection bound to that ListView which will automatically refresh the ListView. We have updated you in our previous sample how to update/delete the swiped item in underlying collection. 
 
If you need to update the ListView in another page, you can just achieve by changing the underlying data collection bound to it. We don’t know whether you are maintaining different collection for each ListView hence please share the ListView related snippets and your application workflow with ListView in both the pages which will be helpful for us to assist you further. 
 
Regards, 
Sangeetha Raju. 



MU Murat September 18, 2019 02:58 PM UTC

Hi Raju, 

I couldn't see your updated sample. I am sharing the code snippets. 

The use cases are; 
- A user's income and expenses are listed in SfListView which is within FinancialPage 
- The user is able to delete an income/expense item via swiping right. With your help, I have succeeded to get income list refreshed if I delete an income item by swiping. 
- The user is able to update an income/expense item via swiping right. If they click on update in swiping, Upsert*** page is opened. After the user update the item in this page, it returns to the FinancialPage where I want to list get refreshed with updated values of income. 
- Insert income/expense item with toolbar buttons named "Gelir Ekle" or "Gider Ekle"is also handled in Upsert*** page, so if user adding an item, returned FinancialPage should be refreshed with new added item. 

Income and Expense are nearly the same items so, it is okay for me to get a sample for one of them. 


Attachment: SFListView_CUD_286e3751.zip


GP Gnana Priya Namasivayam Syncfusion Team September 19, 2019 01:01 PM UTC

Hi Murat, 
 
We have  prepared the sample based on your requirement to edit and update the ListView in new page. To achieve your requirement, we have passed the listview BindingContext to NewPage along with that it is necessary to implement property changed for the model properties binded. We have attached the model sample and code snippet for your reference, please find the sample from below. 
 
 
 
 
public class MainPageViewModel : BindableBase, INavigationAware 
{ 
 
   public Command<object> EditCommand { get; set; } 
 
   public MainPageViewModel() 
   { 
       EditCommand = new Command<object>(OnSwipeEdit); 
   } 
   private void OnSwipeEdit(object obj) 
   { 
      var swipedItem = obj as Contacts; 
      var newPage = new NewPage(); 
      newPage.BindingContext = swipedItem; 
      OnResettingSwipeView(new ResetEventArgs()); 
      App.Current.MainPage.Navigation.PushAsync(newPage); 
   } 
} 
 
 
Can you please check with the above sample whether it meets your requirement. 
 
Regards, 
Gnana Priya N 



MU Murat September 20, 2019 11:48 AM UTC

Hi Gnana, 

This sample is working on its own. However, I couldn't adjust it to my solution. 

1. I already have bahavior classes (BehaviorBase, CustomBehavior, CustomConverter) for SfList, so I couldn't add your Behavior.cs into the existing classes (please see attached files) 
Your Behavior.cs is referred to a named viewmodel class but I need a generic one, since this olution would be implemented to more pages with SfListView.

2. In the first try, my Upsertpage not worked properly, then I have added the binding statement from UpserExpense.xaml.cs 
With changes below, returned page not refreshed unfortunately.

        private void UpdateExpenseTapped(object obj)
        {
            var itemData = obj as ExpenseDetail;

            var upsertPage = new UpsertExpense(true, 0, itemData.ID);
            upsertPage.BindingContext = itemData;
            upsertPage.BindingContext = new UpsertExpenseViewModel(true, 0, itemData.ID); // from UpsertExpense.xaml.cs 
            OnResettingSwipeView(new ResetEventArgs());

            App.Current.MainPage.Navigation.PushAsync(upsertPage);
        }

        public event EventHandler ResetSwipeView;

        protected virtual void OnResettingSwipeView(ResetEventArgs e)
        {
            EventHandler handler = ResetSwipeView;
            handler?.Invoke(this, e);
        }

        public class ResetEventArgs : EventArgs
        {
            public SfListView ListView { get; set; }
        }

When returned from Upsert page, FinancialPage seem without resetting swiping and NOT updated list item. 





Attachment: SFListView_CUD_2_e21b29ad.zip


GP Gnana Priya Namasivayam Syncfusion Team September 23, 2019 12:25 PM UTC

Hi Murat, 
 
 
We have checked your code snippet attached in zip files. We would like to inform that BindingContext of SwipeTemplates will be the Model data which is binded to the ItemTemplates. The reason for not updating is that you have defined both ExpenseDetail Model and UpsertExpenseViewModel as inside UpdateExpenseTapped method. If BindingContext passed properly, then ListViewItem will update and its content as expected.  
 
 
private void UpdateExpenseTapped(object obj) 
{ 
            var itemData = obj as ExpenseDetail; 
 
            var upsertPage = new UpsertExpense(true, 0, itemData.ID); 
            upsertPage.BindingContext = itemData; 
 
            upsertPage.BindingContext = new UpsertExpenseViewModel(true, 0, itemData.ID); // from UpsertExpense.xaml.cs  
            OnResettingSwipeView(new ResetEventArgs()); 
 
            App.Current.MainPage.Navigation.PushAsync(upsertPage); 
} 
 
 
 
We suspect that the reported issue occurs only in certain scenario of your application. In order to find the exact cause for the reported issue, can you please replicate the problem in simple sample if possible or else we can schedule the web meeting to resolve the reported issue in order to avoid further delay.   
  
Regards, 
Gnana Priya N 


Loader.
Live Chat Icon For mobile
Up arrow icon