Guidance on ObservableCollection and SQLite

unixbobunixbob Member ✭✭


I'm writing an app for a friend who does some charity work. I'm not an experienced Xamarin, c# or .Net developer. And I learn by seeing some working code, breaking it and then understanding what the docs are telling me.

Given that haphazard approach, surprisingly I've got 95% of the app working. But I'm completely stuck on populating an ObservableCollection from SQLite. I'm doing this because of the way they want to represent the data they're recording and the SyncFusion SFChart does what they want.

I can populate the charts using OberservableColections of data hard coded in a class. I can populate ListView's from the SQLite database using LINQ and SQLiteAsyncConnection . For those parts I think I've got a decent understanding of what I'm doing (and I've bought a set of courses from Udemy to learn it properly). However I'm really struggling to populate the Observable Collections the Syncfusion charts need when I try pull the data from SQLite.

After lots of searching and trial and error, I'm coming across both very little in the way of worked examples of ObservableCollections and SQLite. But also comments to other peoples questions on StackExchange effectively saying "it's easy, stop asking basic questions". Which leads me to think that I'm approaching the problem in the wrong way.

All of that pre-amble is effectively me saying I've done lots of research, I've got a lot of the way on my own, and I'm not asking for someone to write my code for me. But I think my lack of knowledge in Xamarin / C# / .NET means I'm trying to solve the problem in the wrong way. So given the same problem, how would you approach it? Just trying to get a feel as to whether I should keep banging my head against this brick wall or I should try a different approach that is obvious to more experienced developers


Best Answers


  • NMackayNMackay GBInsider, University mod

    Can you not just query your SQLite data into a class that binds to the chart to make it easy for the chart to consume? So you'd have an ObservableCollection

  • unixbobunixbob Member ✭✭

    That's what I've been looking at trying to do. With everything else being relatively simple to wrap my head around, this seems much harder to accomplish. I initially thought I was missing some key point, but been struggling with this piece for over a week. Hence my thought I might be approaching it in wrong way.

    Your response tells me that I'm missing something key in my understanding but the approach I'm taking is correct.

    Thanks for replying

  • unixbobunixbob Member ✭✭

    Hey chaps

    Thanks for your responses and suggestions. Most of those examples I had looked at. But your feedback that I was doing the right thing made me look at them again and I've got it working now (along with a some help on the syncfusion forums).

    Just wanted to show appreciation for your help. Also, didn't want to just post my code because that felt like I was asking someone else to solve my problem for me (and it's probably an awful mess :blush: ). Thanks again



Sign In or Register to comment.