Trying to bind make a gridview autoupdate in uwp c#

115 Views Asked by At

i want to make a dbgrid update data from a list when i write into it in a uwp. Because you set the datasource in xaml i cant seem to find a way to auto update it? i have tried to use a observablecollection but i cant seem to figure out how it works.

            foreach (var item in dataAccess.GetData())
            {
                cars.Add(item);
            }

this is how i read the values into the list and it runs on a timer so it will add data every time the timer ticks and then the data should display in the dbgrid.

List<CarSimulation> cars = new List<CarSimulation>();

that is how i declaired the lsit that i am using to bind the data to the dbgrid and because i am reading the data from a sqlite database first the dbgrid does not display anything. any tips on how i can update it dynamically?

1

There are 1 best solutions below

2
Vignesh On

Simply change List into ObservableCollection. ObservableCollection is a collection class that provides notifications when items get added or removed.

ObservableCollection<CarSimulation> cars = new ObservableCollection<CarSimulation>();

Here's an example that's already in the community