I need to count and present distinct/unique values in a dataGridView. I want to present it like this, and this code works just fine with lists.
List<
This will work for your example:
var result = dataGridView1.Rows.Cast() .Where(r => r.Cells[0].Value != null) .Select (r => r.Cells[0].Value) .GroupBy(id => id) .OrderByDescending(id => id.Count()) .Select(g => new { Id = g.Key, Count = g.Count() });