开发者

Get notified when list of custom type property is changed?

I have a class and one of the properties is a list of a custom class.

The caller gets the list and is adding instances of class to the list. How do I get notified that the list has been updated?

Private _list as List(of MyType)
Private _totalField1 as Integer

Public Property MyTypeList As List(Of MyType)
    Get
        Return _list
    End Get
    Set(ByVal value As List(Of MyType))
        _list= value
        _totalField1 = _list.Sum(Function(x) x.Field1)
    End Set
End Property

What I'm trying to do is every time a MyType object is added to the list keep a running total of Field1, but adding to the list doesn't use the setter. How can I know when t开发者_开发知识库he list has been added or changed?


you could use BindingList class, rather than List BindingList has events fired when any item is changed/added/deleted.

see for example: http://www.codeproject.com/KB/grid/BindingListExamples.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜