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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

150904 Jan 23,2020 07:45 PM UTC Jan 27,2020 01:03 PM UTC Xamarin.Forms 5
loading
Tags: SfListView
Aram
Asked On January 23, 2020 07:46 PM UTC

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.



Gnana Priya Namasivayam [Syncfusion]
Replied On 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 


Aram
Replied On 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

Lakshmi Natarajan [Syncfusion]
Replied On 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 


Aram
Replied On 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.

Lakshmi Natarajan [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon