简体   繁体   English

显示除 DataGridView 之外的 Linq IEnumerable 的问题

[英]Problem showing Linq IEnumerable Except to DataGridView

I have two hashsets that I want to except to get the distinct data:除了获取不同的数据外,我有两个哈希集:

var dataA = new HashSet<string>();
var dataB = new HashSet<string>();
var exceptA = dataA.Except(dataB);
var exceptB = dataB.Except(dataA);
var result = exceptA.Union(exceptB);
var container = new HashSet<string>(result);
dgv_B.DataSource = container.ToList();

My problem is when I insert the container into the datageid, this is my result:我的问题是当我将容器插入 datageid 时,这是我的结果:

结果

And this is the raw data from breakpoints:这是断点的原始数据:

在此处输入图像描述

How can I display the text in the DGV?如何在 DGV 中显示文本?

The answer was given by fellow @GoodNightNerdPride: @GoodNightNerdPride 的同事给出了答案:

It seems that the DGV does not work with lists of primitive types. DGV 似乎不适用于原始类型列表。 It expects objects and analyzes their properties to generate the columns (a string has a Length property).它期望对象并分析它们的属性以生成列(字符串具有 Length 属性)。 Try something like this instead:尝试这样的事情:

dgv_B.DataSource = container.Select(s => new { Value = s }).ToList();

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

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