How to filter a sub list which is part of another list in C# -
i want filter list part of list.
consider,
class mainclass
properties string name string mainaddress list<subclass> extrainfo
class subclass
properties string address string city string phoneno
now have 10 items in list , each item in list has 2 extrainfo items list items.
now want filter list items condition city == "new york".
so, 10 items in main list (list) should have extrainfo (list) items based on filter condition.
i mean want filter sub list not main list.
thanks in advance!
sample data name mainaddress extrainfo address city phone no
1. vimal bangalore north street new york 654564646 --->sub item 1 north street california 464654565 --->sub item 2
- hareesh chennai north street washington 546466466 --->sub item 1 tower b new york 464645465 --->sub item 2
after filter (condition city == "new york"), should output in main list
name mainaddress extrainfo address city phone no
1. vimal bangalore north street new york 654564646 --->sub item 1
- hareesh chennai tower b new york 464645465 --->sub item 1
hope helps!
you have filter each of sublists:
list<mainclass> mainlist = ... foreach(mainclass main in mainlist) { icollectionview view = collectionviewsource.getdefaultview(main.extrainfo); view.filter = extrainfofilter; } bool extrainfofilter(object obj) { extrainfo item = (extrainfo)obj; return item.city == "new york"; }
Comments
Post a Comment