繁体   English   中英

绑定字典<string, list<string> &gt; 到 C# 中的 DataGridView</string,>

[英]Binding Dictionary<String, List<String>> to DataGridView in C#

如何将Dictionary<String, List<String>>绑定到 C# 中的 DataGridView?

就像是:

var l = from row in listValues select new { Item = row.key, Elements = row.Value };
DatagridView.dataSource = l;

呃,我不会……但如果你愿意,你可以:

yourDataGridView.DataSource = dictionary.Select(x => new {
  PK = x.Key,
  Name = x.Value[0];
  Email = x.Value[1];
  Address = x.Value[2];
}).ToArray();

假设字典值中的List<string>是 3 个字符串的列表,即人名、email 和地址。 即字典的创建类似于/看起来像:

var d = new Dictionary<string, List<string>> {
  {"person1", new List<string>{ "anna", "anna@mail.com", "1 the street" }},
  {"person2", new List<string>{ "caius", "caius@gmail.com", "2 the street" }}
};

暂无
暂无

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

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