簡體   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