如何将数据从词典添加到列表视图控件 [英] How to add Data from a Dictionary to a List View Control

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

问题描述

(这是我

(Its a continution fo my question. Now i'm having a dictionary

Dictionary<String, List<String>>MyDict = new Dictioanary<String, List<String>>(); 

其中包含

"A"           { "A1", "", "" } 
"B"           { "B1", "B2", "" } 
"C"           { "C1", "C2", "C3" } 

我需要将此数据添加到列表视图中

i need to add tthis data to a list view

在这里,字典键是列"标题,值"是每个单元格中的项目

Here the dictionary key is the Column header and Value is the item in each cell

所以最后ListView会像

使用嵌套的for循环我们可以做到这一点,但是有什么方法可以使用LINQ做到这一点.

Using nested for loop we can do this, but is there any way to do this using LINQ.

推荐答案

有什么方法可以使用LINQ做到这一点.

is there any way to do this using LINQ.

可能的是,如果折磨到折断点以上.但是,这并不是LINQ擅长的地方.如果您当前使用循环的方法行得通,那就坚持下去.

Possibly, if you torture it beyond breaking point. However, that isn't really where LINQ excels. If your current approach with a loop works, stick with that.

一些助手:

  • 未定义字典中键的顺序;您应该注意(除非您进行明确排序){"C","A","D","B"}是完全有效的键顺序(无论您添加它们的顺序如何)
  • 可能想考虑ILookup<TKey,TValue>,它描述了每个键和多个值之间的多重映射;默认值(Lookup<TKey,TValue>)是不可变的,但是编写可变的变量很容易.
  • the ordering of keys in a dictionary is not defied; you should note that (unless you sort explicitly) {"C","A","D","B"} is a perfectly valid key order (regardless of what order you added them)
  • you might want to consider ILookup<TKey,TValue>, which describes a multi-map between a each key and multiple values; the default (Lookup<TKey,TValue>) is immutable, but it is easy enough to write a mutable variant.

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

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