Can't change items source of SfListView

Hi, I have a problem with SfListView items source when I programmatically change items source of my list,(for example on button click,add new item and refresh view) view does not get updated,it only updates after page reload. Can you please give me some advices?

5 Replies

VR Vigneshkumar Ramasamy Syncfusion Team July 27, 2018 10:24 AM UTC

Hi Mirza 
 
Thanks for contacting Syncfusion support. 
 
When ItemsSouece is derived from INotifyCollectionChanged ListView will update the UI for add and remove cases. For example, if you use ObservableCollection , ListView will update the UI automatically. Could you please check the type of data collection used in your project? 
 
We have prepared a sample for adding item dynamically in the button click. Please find the sample from the below link. 
 
Sample : ListView_Sample
 
 
Please let us know if this help full. 
 
Regards 
Vigneshkumar R 



MI Mirza July 27, 2018 10:29 AM UTC

I use generic list for items source,and now I know that is a problem. Thank you very much for your help.


VR Vigneshkumar Ramasamy Syncfusion Team July 27, 2018 10:44 AM UTC

Hi Mirza 
 
We glad to know that your requirement has been achieved, please get in touch if you required further assistance on this. 
 
Regards 
Vigneshkumar R 



MI Mirza July 27, 2018 12:30 PM UTC

One more question,is it possible to change property of item in items source and get view updated ? 


VR Vigneshkumar Ramasamy Syncfusion Team July 27, 2018 12:48 PM UTC

Hi Mirza, 
 
We can update the property of item in the ListView ItemsSource dynamically, for that model class should be derived from INotifyCollectionChanged interface. Please refer the below UG link for more details.  
 
 
Code snippet: 
public class BookInfo : INotifyPropertyChanged 
    { 
       private string bookName; 
        public string BookName 
        { 
            get { return bookName; } 
            set 
            { 
                bookName = value; 
                OnPropertyChanged("BookName"); 
            } 
        } 
 
 
        public event PropertyChangedEventHandler PropertyChanged; 
 
        public void OnPropertyChanged(string name) 
        { 
            if (this.PropertyChanged != null) 
                this.PropertyChanged(this, new PropertyChangedEventArgs(name)); 
        } 
 
    }  
 
 
We have used same code in the previous attached sample , please refer that. 
 
Please let us know if this help full. 
 
Regards 
Vigneshkumar R 


Loader.
Up arrow icon