列表类型更新

时间:2015-10-20 17:34:10

标签: c# list class listview arraylist

上课

public class SignalRounding
    {
        public DateTime timee { get; set; }
        public string symbol { get; set; }
        public double price { get; set; }
        public double round { get; set; }
    }

创建列表

public static List<SignalRounding> SignalR;
SignalR = new List<SignalRounding>();
ListView.ItemsSource = SignalR;
ListView.Items.Refresh();

添加一些信息

SignalR.Insert(0, new SignalRounding()
                {
                    timee = DateTime.Now,
                    symbol = symbol,
                    price = price,
                    round = round
                });

再次更新

ListView.Items.Refresh();

现在在我的ListView中显示List,但是我想要显示而不是过去10分钟内符号的行数。最后补充说满足条件应该是listview中的第一个。

2 个答案:

答案 0 :(得分:1)

根据我对您的问题的理解,这是一个天真的解决方案。将您的ItemsSource替换为如下所示的Linq表达式进行限制和排序。

using System.Linq;

ListView.ItemsSource = SignalR.OrderByDescending(s => s.timee).Where(s => (DateTime.Now - s.timee).TotalMinutes < 10);

如果您的列表变得非常长,将会考虑一些性能和可伸缩性问题。

如果要显示在过去10分钟内为每个符号添加的行数,它会有所不同,您可能需要编辑GUI来处理输出,该列表是{{ 3}}具有名为SymbolCountLastAdded的属性。如果它更清楚,您可以创建一个名为SymbolCounter的类,并使用它而不是匿名类。

ListView.ItemsSource = SignalR.Where(s => (DateTime.Now - s.timee).TotalMinutes < 10).GroupBy(s => s.symbol, (key, values) => new {Symbol = key, Count = values.Count(), LastAdded = values.Max(s => s.timee)});

如果要过滤以便仅显示给定符号值的行,请使用SignalR.Where(s => s.symbol == "AAPL")....

您可以找到许多Linq扩展方法anonymous objects的文档。这些可以链接并应用于您的初始列表。有很多关于此的教程。

答案 1 :(得分:1)

认为这就是你要找的......这会收集你的SignalR对象列表,过滤任何超过10分钟的符号,按符号分组,并返回列表按时间排序的聚合,然后是数量。

这假设您有一个名为var TESTalpha = spreadsheet.getRange("E4:I4"), TESTalphaData = TESTalpha.getValues(); var col = TESTalphaData[0].length; // use a meaningful name for a variable while( --col >= 0 ) { // Make the tests and assign the variable the array you pulled from the sheet with getValues(), it's exactly the same you need to input with setValues() if (TESTalphaData[0][col ] == "f") { TESTalphaData[0][col] = 'FAB'; } else if (TESTalphaData[0][col] == "p") { TESTalphaData[0][col] = "PAINT"; } else if (TESTalphaData[0][col] == "c") { TESTalphaData[0][col] = "FINISH"; } // Setting the values should be after the loop is complete, so I removed it from inside the for (now a while), to the end of the code } // No need to get the Ranges again, you already save it up there // No need to clear the range, it will all be re-written again TESTalpha.setValues(TESTalphaData); 的ListView(请不要将对象命名为与其类相同的对象)。

注意:我添加了对lv的调用,只是为了在此示例中返回一些不同的时间戳;这显然不应该在你的代码中。

Thread.Sleep()