Home > Blockchain >  Problem showing Linq IEnumerable Except to DataGridView
Problem showing Linq IEnumerable Except to DataGridView

Time:09-08

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:

result

And this is the raw data from breakpoints:

enter image description here

How can I display the text in the DGV?

CodePudding user response:

The answer was given by fellow @GoodNightNerdPride:

It seems that the DGV does not work with lists of primitive types. It expects objects and analyzes their properties to generate the columns (a string has a Length property). Try something like this instead:

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