简体   繁体   中英

Trying to bind make a gridview autoupdate in uwp c#

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM