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 + DataSource + Realm example

Hi,

Is there any example with SfListView + DataSource + Realm(Database) + MVVM.
I want to know the correct way to use SfSlistView with those to CRUD and Filter.

I tried but I don't know it's the correct way.

1. I tried to get Realm.All<obj> to ObservableCollection.
2. I set the collection to the listview binding ItemSource.
3. When deleting Item, If I only delete the Realm Object, and reassign the ItemSource to the Realm.All<obj>().ToObservableCollection. it won't refresh the listview, even though I set the DataSource.Refresh().
4. Right now I delete the item in the collection and realm object at the same time, but I don't think it's a good idea.

so is there any example to use all of those tech. to implement CRUD, Filter, Sorting function?

7 Replies

DB Dinesh Babu Yadav Syncfusion Team July 17, 2017 09:56 AM UTC

Hi Seven, 
 
Thank you for using Syncfusion Products. 
 
We have checked the reported requirement “SfListView with Realm sample in MVVM pattern” at our end and tried to implement the SfListView control with Realm in MVVM pattern but we are facing the following error “Fody/RealmWeaver: Class Contacts is a RealmObject but has no persisted properties” at our end. So, we have raised a ticket to the respective team to resolve the issue and you can find the link below. 
 
 
For your reference, we have attached the prepared sample in which SfListView with Realm in MVVM pattern has been implemented and you can download it from the below link. 
 
 
Could you please check with the above sample? If you could able to resolve the issue, we request you to modify the above sample and revert us if the requirement does not met with the additional information’s which would help us to analyze the requirement better and update you an appropriate solution. 
 
Regards, 
Dinesh Babu Yadav 



SE seven July 19, 2017 06:03 AM UTC

Hi,

I tried your sample, and I don't think line 78 can work.

contactsinfo = _realm.All<Contacts>() as ObservableCollection<Contacts>;

the cast will make contactsinfo null.



SE seven July 20, 2017 03:28 AM UTC

Hi,

I still suffer in this thread.

I tried a really easy sample.

Listview worked at Create item and Modify item. but when delete item, it didnt update the listview.

I checked the IEnumerableCollection changed after delete command.

Please give me a hand asap, thanks a lot!!


Attachment: code_snippet_87abda3c.rar


SE seven July 20, 2017 05:29 AM UTC

by the way,

I also use dataSource.Refresh and listview.RefreshView,

The UI display weird.

very suffer to me....



MK Muthu Kumaran Gnanavinayagam Syncfusion Team July 24, 2017 03:50 AM UTC

Hi Seven, 
  
Apologies for the delay. 
  
We have deeply analyzed the reported query “ListView items does not refresh after deleting the items from Realm collection” at our end. We would like to inform you that the SfListView refreshes the view only when it gets notification whether underlying collection is changed or modified. Adding/removing items through Realm doesn't notify whether the collection is changed and so the view does not update even while calling the RefreshView. So we have to store the realm objects under ObservableCollection(As it provides notification when collection changed) to refresh the view. 
  
For your assistance, we have attached the working sample link below, 
  
Please let us know if you further assistance. 
  
Regards, 
G.Muthu Kumaran. 



RE redhouane May 27, 2018 08:42 AM UTC

Hi,
I wonder why it works with the out of the box ListView

thanks in advance


MK Muthu Kumaran Gnanavinayagam Syncfusion Team May 30, 2018 12:50 PM UTC

Hi Redhouane, 
 
We would like to inform you that while modifying the IEnumerable collection(either adding or deleting items at runtime) will update the items list bound to the ItemsSource of ListView. However the View will not be updated as the source collection will not get notified regarding this change. We have checked the same with Xamarin.Forms ListView and found the similar behavior as stated earlier. So you need the store the underlying collection as ObservableCollection to perform Visual changes at runtime in ListView. 
 
Regards, 
G.Muthu kumaran. 


Loader.
Up arrow icon