c# - How do I update a single item in an ObservableCollection class? -
how update single item in observablecollection class?
i know how add. , know how search observablecollection 1 item @ time in "for" loop (using count representation of amout of items) how chage existing item. if "foreach" , find item needs updating, how put observablecollection>
you don't need remove item, change, add. can use linq firstordefault
method find necessary item using appropriate predicate , change properties, e.g.:
var item = list.firstordefault(i => i.name == "john"); if (item != null) { item.lastname = "smith"; }
removing or adding item observablecollection
generate collectionchanged
event.
Comments
Post a Comment