如何将特定列数据从datagridview添加到listview [英] How to add specific column data from datagridview to listview

查看:70
本文介绍了如何将特定列数据从datagridview添加到listview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我写了一个应用程序,它读取两个CSV文件(入口和出口),每个文件包含11列,并在一个文件中使用两个datagridviews显示它们窗口。每人有多个条目(记录)。现在,我的Windows窗体应用程序必须能够创建一个摘要,其中只包含每个人的单个实例,并显示第一个CSV的第一个条目(时间)和同一个CSV中的最后一个条目,任何想法?

Hi everyone,

I wrote an application that reads two CSV files(Entry and Exit) which contains 11 columns each and displays them using two datagridviews on a single window. There are multiple entries per person (record). Now, my windows form app must be able to create a summary which will contain just a single instance of each person, and show their first entry(time) from the first CSV and a their last entry from the same CSV, any ideas?

推荐答案

我猜你在使用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();


这篇关于如何将特定列数据从datagridview添加到listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆