Imagine... You have a data. You store it in a
DataTable[
^] object, which is a
DataSource[
^] of your
DataGridView[
^] object.
Take a look at below code. There you'll find an example - how to group data by using Linq.
Sub Main
Dim dt As DataTable = CreateSampleData()
Dim result = dt.AsEnumerable() _
.GroupBy(Function(x) x("DuplicatedDate")) _
.Select(Function(grp) New With _
{ _
.DupDate = grp.Key, _
.OrigValues = String.Join(", ", grp.Select(Function(x) x("SomeNumbers"))), _
.MinValue = grp.Min(Function(x) x("SomeNumbers"))
}) _
.ToList()
result.Dump()
End Sub
Public Function CreateSampleData() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("SomeDate", Type.GetType("System.DateTime")))
dt.Columns.Add(New DataColumn("SomeNumbers", Type.GetType("System.Int32")))
dt.Columns.Add(New DataColumn("DuplicatedDate", Type.GetType("System.DateTime")))
Dim r As New Random()
For i As Integer = 1 To 20
Dim j As Integer = (i Mod 4) + 1
dt.Rows.Add(New Object(){New DateTime(2020, 3, i), r.Next(1,20), New DateTime(2020, 3, j)})
Next i
Return dt
End Function
Sample result:
DupDate OrigValues MinValue
2020-03-02 00:00:00 12,13,7,2,17 2
2020-03-03 00:00:00 16,11,9,5,13 5
2020-03-04 00:00:00 3,7,13,19,8 3
2020-03-01 00:00:00 16,14,7,6,13 6