I have dataGridView1 containing two columns, Col1 and Col2, both contain duplicate values.
Column1 | Column2
2515 | 1105
1105 | 2515
3800 | 2208
2515 | 1105
2508 | 3800
I need to count repetition of values from both columns by selecting only values starting with 25 then show the result in dataGridView2 which consists of Columns: Id, Value, and Repetition, after clicking on a button.
I tried the following but miss the condition to select and count only values start with 25:
var s1 = dt.AsEnumerable().Select(r => r.Field<string>("Column1")).ToList();
var s2 = dt.AsEnumerable().Select(r => r.Field<string>("Column2")).ToList();
List<string> list = new List<string>();
list.AddRange(s1);
list.AddRange(s2);
var result = list.GroupBy(x => x)
.Select(g => new { Value = g.Key, Count = g.Count() })
.OrderByDescending(x => x.Count);
int count = 1;
dataGridView2.Columns.Add("Id", "");
dataGridView2.Columns.Add("Value", "");
dataGridView2.Columns.Add("Repetition", "");
foreach (var item in result)
{
dataGridView2.Rows.Add(count, item.Value, item.Count);
count++;
}
How can I count values start with 25** from datagridview1 and show them in dataGridView2?
Appreciate your help!
