I want to delete all items in ListView1 except youngest student in each group by comparing their date of births.
So, I tried to create a structured database and binding it to my ListView1 but failed with errors & exceptions.
Any help is greatly appreciated.
This is my code-
// assume 'Students is a List<Student>
IEnumerable<Student> earlydatestudents = Students.GroupBy(std => std.Group)
.Select(grp =>
{
DateTime dt = grp.Min(s => s.DOB);
return grp.Where(st => st.DOB == dt);
})
.SelectMany(slist => slist);
var toDeleteList = Students.Except(earlydatestudents).ToList();
//
My ListView1 contains-
Student , DOB , Location
Group1
AAA 10-05-2000 Mumbai
BBB 05-02-2000 Pune
CCC 01-01-2000 Delhi
Group2
DDD 20-03-1999 Lucknow
EEE 15-06-1999 Chennai
FFF 18-09-1999 Ahmedabad