[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Do we need to use both ObservableCollection and INotifyPropertyChanged in order to have all three features (Add/Update/Delete) enabled - WPF ?

Posted on 2011-05-04
Medium Priority
Last Modified: 2012-08-13

Can you please let me know:

Do we need to use both ObservableCollection and INotifyPropertyChanged in order to have all three features (Add/Update/Delete) enabled - WPF ?

If yes, can you please provide me a simple example on this ?

Question by:milani_lucie
LVL 18

Accepted Solution

lludden earned 1000 total points
ID: 35694231
From MS page about Observable collection:
The objects in your collection must satisfy the requirements described in the Binding Sources Overview. In particular, if you are using OneWay or TwoWay (for example, you want your UI to update when the source properties change dynamically), you must implement a suitable property changed notification mechanism such as the INotifyPropertyChanged interface.

Here is a sample from one of my classes
Public Class Payor
    Implements INotifyPropertyChanged

Open in new window

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
    Private _AuthorizationRequired As Boolean

    Protected Overridable Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)
        RaiseEvent PropertyChanged(Me, e)
    End Sub

    Public Property AuthorizationRequired() As Boolean
            Return _AuthorizationRequired
        End Get
        Set(ByVal value As Boolean)
            _AuthorizationRequired = value
            OnPropertyChanged(New PropertyChangedEventArgs("AuthorizationRequired"))
        End Set
    End Property

Author Comment

ID: 35694325
Can you please provide sample client code which is binding to a Grid ? I mean consumer code of this collection.

LVL 40

Assisted Solution

mrjoltcola earned 1000 total points
ID: 35694817
For Add/Delete you need INotifyCollectionChanged.CollectionChanged  - http://msdn.microsoft.com/en-us/library/ms653375.aspx

As far as Update, you need to clarify: Update of what? If you are interested in when an item is replaced, then the CollectionChanged event covers that too, but if you want to know if a property of an item in the collection changed, you need INotifyPropertyChanged to be implemented on the item class itself.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question