BindingList.ListChanged Event not Raised when Property Changes
Asked Answered
I

2

6

I have a BindingList of type User, the User object has several properties (UserName, Password, etc). So I tied an event handler to the BindingList.ListChanged event, and it works fine when adding or deleting a user, BUT, if a user property changes, it does not raise the event, is there any way to achieve this?

bindingListUsers.Add(someUser); // This raises ListChangedEvent

bindingListUsers.Delete(someUser); // This raises ListChangedEvent

bindingListUsers[0].UserName = "Another user name"; // This does NOT raise the event
Ical answered 7/5, 2009 at 15:30 Comment(2)
I would request you to reframe your question. These 2 words in question doesnt tell much about the problem you are trying to solve.Extrauterine
Newer answer here where I commented about my own specific problem inheriting the BindingList class in my own custom class.Extravaganza
A
10

Your User type need to implement INotifyPropertyChanged.

Abutment answered 7/5, 2009 at 15:41 Comment(2)
Beautiful! This did the job. Thank you so much!Ical
If the type is not going to implement INotifyPropertyChanged is there a way to raise the ListChangedEvent in code? (so that bound UI elements can respond to it)Chloral
E
0

The only way I can think of is define an event in User class which is fired when a property value is changed (you have to write code manually for that). Then create a wrapper class of binding list. Handle both list events and user class events in that class.

I can elaborate more if you like the idea...

Extrauterine answered 7/5, 2009 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.