Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within C# and .NET
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
C# and .NET
C# ListView Delete Items With Condition
Yof Raja
Greenhorn
Posts: 1
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Sorry for posting in
Java
forum, I couldn't find C# forum over here.
I've created a ListView1 in C#
This ListView1 contains the columns: Student, DOB and Location.
There are different groups. Each student is grouped together with other students sharing the same age group.
The DOB field is in date format representing date of birth of each student.
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
Can you please help me with the Code to automatically delete all items except the youngest student in each of the groups (by comparing DOB)?
Thanks a lot in advance.
Sherin Mathew
Ranch Hand
Posts: 95
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
By this logic you can remove items except the youngest one::
var studentList = new List<Tuple<string, DateTime, string>>(); studentList.Add(new Tuple<string, DateTime, string>("AAA", new DateTime(2000, 05, 10).Date, "Mumbai")); studentList.Add(new Tuple<string, DateTime, string>("BBB", new DateTime(2000, 02, 05).Date, "Pune ")); studentList.Add(new Tuple<string, DateTime, string>("CCC", new DateTime(2000, 01, 01).Date, "Delhi")); var younger = studentList.OrderByDescending(x => x.Item2).LastOrDefault(); studentList.RemoveAll(x=>x!=younger); foreach(var item in studentList) { Console.WriteLine(item); }
.NET Developer at iFour Technolab Pvt LTd
This one time, at bandcamp, I had relations with a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to split a string by the whitespace but ignoring '\n'?
array
following::* doubt
Regex split text around quotes
Preceding siblings
More...