Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
'//sample datasource
Dim dt = New DataTable()
With dt.Columns
'//add columns
.Add("StoreId", GetType(Integer))
.Add("DateStamp", GetType(Date))
.Add("Guid", GetType(Guid))
End With
With dt.Rows
'//add rows
.Add(1, Date.Now.Date, Guid.NewGuid())
.Add(1, Date.Now.Date, Guid.NewGuid())
.Add(2, Date.Now.AddDays(1.0R).Date, Guid.NewGuid())
.Add(3, Date.Now.AddDays(2.0R).Date, Guid.NewGuid())
.Add(2, Date.Now.AddDays(1.0R).Date, Guid.NewGuid())
.Add(1, Date.Now.AddDays(1.0R).Date, Guid.NewGuid())
End With
'//set datasource
Me.DataGridView1.DataSource = dt
'//highlighting code
Dim query = dt.AsEnumerable() _
.GroupBy(Function(key) _
New With {Key .StoreId = _
key.Field(Of Integer)("StoreId"), _
Key .DateStamp = _
key.Field(Of Date)("DateStamp")}) _
.Where(Function(g) g.Count() > 1) _
.Select(Function(g) g.Key)
'//Sql Translation
'// SELECT dt.StoreId, dt.DateStamp
'// FROM(dt)
'// GROUP BY dt.StoreId, dt.DateStamp
'// HAVING (((Count(dt.DateStamp))>1));
For Each row As DataGridViewRow In Me.DataGridView1.Rows
For Each anon In query
Dim storeId = row.Cells("StoreId").Value
Dim dateStamp = row.Cells("DateStamp").Value
If Object.Equals(storeId, anon.StoreId) AndAlso _
Object.Equals(dateStamp, anon.DateStamp) Then
'//row is a duplicate
row.DefaultCellStyle.BackColor = Color.Red
End If
Next
Next
End Sub
End Class