简体   繁体   English

使用列表中的项目填充listView控件<ListViewItem>

[英]Populate listView control with items from a List<ListViewItem>

I have four List<ListViewItem> and one listView control . 我有四个 List<ListViewItem>一个 listView control

What I want is to populate the control with the items from the lists. 我想要的是用列表中的项目填充控件。

How can I do it? 我该怎么做?

What I would do is first merge the four lists into one and then add them to the ListView's Items collection. 我要做的是先将四个列表合并为一个,然后将它们添加到ListView的Items集合中。

var allListItems = list1.Concat(list2)
                        .Concat(list3)
                        .Concat(list4)
                        .ToList();

listView.Items.AddRange(allListItems);

This is not very pretty or the best performing solution but it does the job. 这不是很漂亮,也不是性能最好的解决方案,但是可以完成工作。 Take a look at this thread to get a better idea on how to merge more than one list to one. 看一下这个线程 ,可以更好地了解如何将多个列表合并为一个列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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