Latest data in the first row
Goal:
Have the latest data to be in the first row and not in the end of listview. The program is in WPF.Problem:
Based on this source code, don't know how to recieve the latest data in the first row in the listv开发者_高级运维iewFor the sake of simplicity, that sample code is loading hard-coded data into the ListView. It isn't retrieving live data from a database, as you will presumably be doing.
If at all possible, you should sort the data when you retrieve it from the database. Then you'll have no problem just binding that sorted data to your ListView
Get the current date/time from your data source and sort on that, descending. For example, if you are reading the records from an SQL Server database, include a field GETDATE() AS date_time
. If the data is from a file, use the built-in .NET date/time objects (Now
in VB.NET) to add the timestamp.
You need to provide the data to the listview in a sorted fashion.
This example shows one way.
You could also expose the data through a viewmodel that would wrap some model (possibly whatever source list you're looking at), sort it (probably using a linq .orderyby method) and give the data to your view.
精彩评论