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
close icon

sfListView order is not updated, when i reorder the source ObservableCollection.

I have a sfListView that shows a collection of my class Moznosti that is implemeted like this:
public class MoznostSerazeni : INotifyPropertyChanged
   {
       private string text;
       private bool serazeno = false;
       public string Text
       {
           get { return text; }
           set
           {
               text = value;
           }
       }
       public bool Serazeno
       {
           get { return serazeno; }
           set
           {
               serazeno = value;
               OnPropertyChanged("Poradi");
           }
       }
 
       public event PropertyChangedEventHandler PropertyChanged;
       public void OnPropertyChanged(string name)
       {
           if (this.PropertyChanged != null) { 
               this.PropertyChanged(thisnew PropertyChangedEventArgs(name));
           }
       }
   }

In my page i create a new ObservableCollection and populate it with data. The List View shows this data as it should.

On that page there is button that reorders this collection, then loops through all of the items and sets its Bool Serazeno to true. This should call OnPropertyChanged many times and if I understand correctly the list should update, but it doesn't. What am I doing wrong here ? 
Thanks for all the help.



5 Replies

GP Gnana Priya Namasivayam Syncfusion Team January 24, 2020 09:38 AM UTC

Hi Aram, 
 
Thanks for contacting Syncfusion support. 
 
We have checked the reported query from our side. We have ordered the collection at runtime in button clicked based on the ContactNumber’s new value like below and collection gets updated based on the new ContactNumber in our sample. We have attached the tested sample and code snippet for your reference, please find them from below. 
 
 
 
 
 
public partial class MainPage : ContentPage 
{ 
        public MainPage() 
        { 
            InitializeComponent(); 
        } 
        private void Button_Clicked(object sender, EventArgs e) 
        { 
            var BC = viewModel.ContactsInfo; 
            for(int i=0;i<BC.Count-1;i++) 
            { 
                if (i % 3 == 0) 
                    BC[i].NewContactNumber = "11111"; 
            } 
            viewModel.ContactsInfo = new ObservableCollection<Contacts>(BC.OrderBy(i => i.NewContactNumber)); 
        } 
} 
 
 
Can you please check with the above code in your sample and kindly check the following, 
  • Whether your ItemsSource collection is ObservableCollection<T>,
  • Whether implemented PropertyChanged for ItemsSource.
 
If reported issue still occurs kindly revert us with the modified sample or issue replicated sample so that we can check your sample in detail and provide appropriate solution at our end. 
 
Regards, 
Gnana Priya N 



AR Aram January 24, 2020 06:40 PM UTC

Hi,
I created a minimal sample by following the example you sent me. Even though I can't see any meaningfull difference between the two, the list view in my project still doesn't refresh as it should. What am I doing wrong here ?

Attachment: ListViewTest_f8df688e.zip


LN Lakshmi Natarajan Syncfusion Team January 27, 2020 10:08 AM UTC

Hi Aram, 
 
Thank you for the update. 
 
We have checked the reported query from our end. We would like to let you know that you need to pass the RaiseOnPropertyChanged method parameter as property name.  
 
For example, you can refer the following code snippet which resolves the issue, 
 
ViewModel: 
 
public ObservableCollection<Item> Items 
        { 
            get 
            { 
                return items; 
            } 
            set 
            { 
                items = value; 
                //Parameter should be the same as PropertyName. i.e., Items 
                this.RaisedOnPropertyChanged("Items"); 
            } 
        } 
 
We have modified your sample and attached in the following link, 
 
 
Please check the sample and let us know if you need any further assistance. 
 
Regards, 
Lakshmi Natarajan 



AR Aram January 27, 2020 11:50 AM UTC

That's it ! 
Thanks for the help, it's amazing to work with your products in that regard.


LN Lakshmi Natarajan Syncfusion Team January 27, 2020 01:03 PM UTC

Hi Aram, 
  
Thank you for the update. 
  
We are glad that reported issue have been resolved at your end. Please let us know if you need any further update. As always we are happy to help you out. 
  
Regards, 
Lakshmi Natarajan 


Loader.
Live Chat Icon For mobile
Up arrow icon