how to do it?
I've fount this code in How to Count Duplicates in List with LINQ :
var list = new List<string> { "a", "b", "a", "c", "a", "b" };
var q = from x in list
group x by x into g
let count = g.Count()
orderby count descending
select new { Value = g.Key, Count = count };
foreach (var x in q)
{
MessageBox.Show("Value: " + x.Value + " Count: " + x.Count);
}
But how to modify it to count duplicates in datagridview? For example datagridview1[7,i] where i is number of rows in datagriview.
EDIT
Now my code is looking like that:
var list = dataGridView1.Rows.OfType<DataGridViewRow>()
.GroupBy(x => x.Cells["TestValues"].Value)
.Select(g => new { Value = g.Key, Count = g.Count(), Rows = g.ToList() })
.OrderByDescending(x => x.Count);
var q = from x in list
group x by x into g
let count = g.Count()
orderby count descending
select new { Value = g.Key, Count = count };
foreach (var x in q)
{
// dataGridView1[7, x].Value.ToString();
MessageBox.Show("Value: " + x.Value + " Count: " + x.Count +"Rows: " );
}