小编Eme*_*rop的帖子

如何将字典绑定到DataGridView的数据源

我认为这个问题很清楚。我有一个 Dictionary 实例,我想像 DataGridView 实例的 DataSource 一样绑定它。其实我可以这样直接绑定:

Dictionary<string,string> d = new Dictionary<string,string>();
d.Add("1","test1");
d.Add("2","test2");
DataGridView v = new DataGridView();

v.DataSource = d;
Run Code Online (Sandbox Code Playgroud)

但没有任何结果。

c# dictionary datagridview

2
推荐指数
3
解决办法
1万
查看次数

设置对象的属性

我想通过LINQ查询获取一个对象列表.问题是我需要设置该对象的属性,但这些属性未在其构造函数中设置.

categories.Select(c => new { c.catId, c.catName, c.catParent })
          .Where(c => c.catParent == id)
          .AsEnumerable()
          .Select(c => new CatInfoType())
          .ToList();
Run Code Online (Sandbox Code Playgroud)

例如,在Select中我需要设置CatInfoType实例的公共属性,如Id,Name等.

c# linq

1
推荐指数
1
解决办法
53
查看次数

标签 统计

c# ×2

datagridview ×1

dictionary ×1

linq ×1