且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将特定列数据从datagridview添加到listview

更新时间:2023-12-01 08:55:58

我猜你在使用CSV读取数据集(数据表)或某些列表来存储数据。如果是这种情况,请使用序列列显示从CSV中获取的记录序列。在此之后,您可以使用linq对此数据集或列表进行查询。首先获取不同名称的列表,然后您可以在排序列表上查询以获取最后一个和第一个项目。有点谎言(我没有测试过!):



I guess you are using dataset (datatable) or some list to store the data after you read from CSV. If that is the case use a sequence column that shows the sequence of the records readed from the CSV. After this you can use linq to make query on this dataset or list. First get the list of the distinct names and then you can query on the sorted list to get the last and the first item. Something liek this (I did not tested!):

var DistinctUsers = (from i in table.AsEnumerable() select new { name = i.Field<string>("UserName") }).Distinct();

                 //foreach DistinctUsers....

                 var firstLast = from i in table.AsEnumerable() orderby i.Field<int>("SeqNumber") select i;

                 firstLast.First();

                 firstLast.Last();