<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Use INotifyPropertyChanged with BindingList</title>
	<atom:link href="http://www.gavaghan.org/blog/2007/07/17/use-inotifypropertychanged-with-bindinglist/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gavaghan.org/blog/2007/07/17/use-inotifypropertychanged-with-bindinglist/</link>
	<description>Mike Gavaghan blogs on Java, C#, .Net, and the software industry</description>
	<lastBuildDate>Sat, 26 Nov 2011 17:37:47 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: andres</title>
		<link>http://www.gavaghan.org/blog/2007/07/17/use-inotifypropertychanged-with-bindinglist/comment-page-1/#comment-222</link>
		<dc:creator>andres</dc:creator>
		<pubDate>Wed, 04 Mar 2009 22:34:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.gavaghan.org/blog/2007/07/17/use-inotifypropertychanged-with-bindinglist/#comment-222</guid>
		<description>Based on this I make a more generic solution thats implements  INotifyPropertyChanged, INotifyPropertyChanging, IEditableObject and other level of manual discard changes. This can be used in this way:

    public class AnyBussinesObjectUIRepresentation : Entities.AnyBussinesObjectBase, IEditableUIObject
    {
        public override bool Active
        {
            get { return editableData.GetData(&quot;Active&quot;); }
            set { editableData.SetData(&quot;Active&quot;, value); }
        }

        public override string Description
        {
            get { return editableData.GetData(&quot;Description&quot;); }
            set { editableData.SetData(&quot;Description&quot;, value); }
        }

        public override string Code
        {
            get { return editableData.GetData(&quot;Code&quot;); }
            set { editableData.SetData(&quot;Code&quot;, value); }
        }

        public override Guid Id
        {
            get { return editableData.GetData(&quot;Id&quot;); }
            set { editableData.SetData(&quot;Id&quot;, value); }
        }

        public override string Name
        {
            get { return editableData.GetData(&quot;Name&quot;); }
            set { editableData.SetData(&quot;Name&quot;, value); }
        }


        #region IEditableUIObject Implementation

        private IEditableUIObjectSupporter editableData = new EditableUIObjectSupporter();

        public event PropertyChangingEventHandler PropertyChanging
        {
            add { editableData.PropertyChanging += value; }
            remove { editableData.PropertyChanging -= value; }
        }

        public event PropertyChangedEventHandler PropertyChanged
        {
            add { editableData.PropertyChanged += value; }
            remove { editableData.PropertyChanged -= value; }
        }

        [IgnoreDataMember]
        public bool DiscartableChangesControl
        {
            get { return editableData.DiscartableChangesControl; }
            set { editableData.DiscartableChangesControl = value; }
        }

        public bool IsDirty
        {
            get { return editableData.IsDirty; }
        }

        public void DiscardChanges()
        {
            editableData.DiscardChanges();
        }

        public void AcceptChanges()
        {
            editableData.AcceptChanges();
        }

        public ValueChangedDescriptorCollection GetChanges()
        {
            return editableData.GetChanges();
        }

        void IEditableObject.BeginEdit()
        {
            editableData.BeginEdit();
        }

        void IEditableObject.CancelEdit()
        {
            editableData.CancelEdit();
        }

        void IEditableObject.EndEdit()
        {
            editableData.EndEdit();
        }

        #endregion
    }

I don&#039;t paste the base code because there are 300 lines but you can see it in http://code.google.com/p/facturanet/source/browse/#svn/trunk/Facturanet.Core/UI

Maybe the Hashtables are not so efficients, but I think that it will be enough for my project. 

Thanks for the inspiration.</description>
		<content:encoded><![CDATA[<p>Based on this I make a more generic solution thats implements  INotifyPropertyChanged, INotifyPropertyChanging, IEditableObject and other level of manual discard changes. This can be used in this way:</p>
<p>    public class AnyBussinesObjectUIRepresentation : Entities.AnyBussinesObjectBase, IEditableUIObject<br />
    {<br />
        public override bool Active<br />
        {<br />
            get { return editableData.GetData(&#8220;Active&#8221;); }<br />
            set { editableData.SetData(&#8220;Active&#8221;, value); }<br />
        }</p>
<p>        public override string Description<br />
        {<br />
            get { return editableData.GetData(&#8220;Description&#8221;); }<br />
            set { editableData.SetData(&#8220;Description&#8221;, value); }<br />
        }</p>
<p>        public override string Code<br />
        {<br />
            get { return editableData.GetData(&#8220;Code&#8221;); }<br />
            set { editableData.SetData(&#8220;Code&#8221;, value); }<br />
        }</p>
<p>        public override Guid Id<br />
        {<br />
            get { return editableData.GetData(&#8220;Id&#8221;); }<br />
            set { editableData.SetData(&#8220;Id&#8221;, value); }<br />
        }</p>
<p>        public override string Name<br />
        {<br />
            get { return editableData.GetData(&#8220;Name&#8221;); }<br />
            set { editableData.SetData(&#8220;Name&#8221;, value); }<br />
        }</p>
<p>        #region IEditableUIObject Implementation</p>
<p>        private IEditableUIObjectSupporter editableData = new EditableUIObjectSupporter();</p>
<p>        public event PropertyChangingEventHandler PropertyChanging<br />
        {<br />
            add { editableData.PropertyChanging += value; }<br />
            remove { editableData.PropertyChanging -= value; }<br />
        }</p>
<p>        public event PropertyChangedEventHandler PropertyChanged<br />
        {<br />
            add { editableData.PropertyChanged += value; }<br />
            remove { editableData.PropertyChanged -= value; }<br />
        }</p>
<p>        [IgnoreDataMember]<br />
        public bool DiscartableChangesControl<br />
        {<br />
            get { return editableData.DiscartableChangesControl; }<br />
            set { editableData.DiscartableChangesControl = value; }<br />
        }</p>
<p>        public bool IsDirty<br />
        {<br />
            get { return editableData.IsDirty; }<br />
        }</p>
<p>        public void DiscardChanges()<br />
        {<br />
            editableData.DiscardChanges();<br />
        }</p>
<p>        public void AcceptChanges()<br />
        {<br />
            editableData.AcceptChanges();<br />
        }</p>
<p>        public ValueChangedDescriptorCollection GetChanges()<br />
        {<br />
            return editableData.GetChanges();<br />
        }</p>
<p>        void IEditableObject.BeginEdit()<br />
        {<br />
            editableData.BeginEdit();<br />
        }</p>
<p>        void IEditableObject.CancelEdit()<br />
        {<br />
            editableData.CancelEdit();<br />
        }</p>
<p>        void IEditableObject.EndEdit()<br />
        {<br />
            editableData.EndEdit();<br />
        }</p>
<p>        #endregion<br />
    }</p>
<p>I don&#8217;t paste the base code because there are 300 lines but you can see it in <a href="http://code.google.com/p/facturanet/source/browse/#svn/trunk/Facturanet.Core/UI" rel="nofollow">http://code.google.com/p/facturanet/source/browse/#svn/trunk/Facturanet.Core/UI</a></p>
<p>Maybe the Hashtables are not so efficients, but I think that it will be enough for my project. </p>
<p>Thanks for the inspiration.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Gavaghan</title>
		<link>http://www.gavaghan.org/blog/2007/07/17/use-inotifypropertychanged-with-bindinglist/comment-page-1/#comment-68</link>
		<dc:creator>Mike Gavaghan</dc:creator>
		<pubDate>Sat, 20 Oct 2007 21:40:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.gavaghan.org/blog/2007/07/17/use-inotifypropertychanged-with-bindinglist/#comment-68</guid>
		<description>Mike,

It sounds like you&#039;re describing object persistence, which is a rather different problem.  I was tackling binary serialization which solely applies to things like remoting or streaming to a file.

My first thought is that, using the approach you&#039;re describing, you probably would not encounter the ser/deser bug.  Your DAOs would be directly instantiating BindingList&lt;T&gt; instances on deserialization - instead of the .NET runtime.  You&#039;d be adding items manually and, thus, reconnecting the events.

However, you might save yourself a lot of grief by adopting NHibernate (http://www.hibernate.org/343.html).  That will handle all of the object-relational mapping needs (like dirty flags, CRUD, etc.) It&#039;s all automagic - you only need to declare your object state.

Unfortunately, NHibernate uses a dynamic implementation of collection classes - not BindingList - so you&#039;d lose the benefits of property change notifications.  You&#039;d need to copy your collections into a BindingList&lt;T&gt; any time change notifcation is needed (and copy everything back to capture changes).  Ugly?  You bet.  But. it&#039;s neither as tedious nor as error prone as coding your entire persistent domain model as handcrafted DAOs.

--Mike</description>
		<content:encoded><![CDATA[<p>Mike,</p>
<p>It sounds like you&#8217;re describing object persistence, which is a rather different problem.  I was tackling binary serialization which solely applies to things like remoting or streaming to a file.</p>
<p>My first thought is that, using the approach you&#8217;re describing, you probably would not encounter the ser/deser bug.  Your DAOs would be directly instantiating BindingList<t> instances on deserialization &#8211; instead of the .NET runtime.  You&#8217;d be adding items manually and, thus, reconnecting the events.</p>
<p>However, you might save yourself a lot of grief by adopting NHibernate (<a href="http://www.hibernate.org/343.html" rel="nofollow">http://www.hibernate.org/343.html</a>).  That will handle all of the object-relational mapping needs (like dirty flags, CRUD, etc.) It&#8217;s all automagic &#8211; you only need to declare your object state.</p>
<p>Unfortunately, NHibernate uses a dynamic implementation of collection classes &#8211; not BindingList &#8211; so you&#8217;d lose the benefits of property change notifications.  You&#8217;d need to copy your collections into a BindingList</t><t> any time change notifcation is needed (and copy everything back to capture changes).  Ugly?  You bet.  But. it&#8217;s neither as tedious nor as error prone as coding your entire persistent domain model as handcrafted DAOs.</p>
<p>&#8211;Mike</t></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike DiRenzo</title>
		<link>http://www.gavaghan.org/blog/2007/07/17/use-inotifypropertychanged-with-bindinglist/comment-page-1/#comment-67</link>
		<dc:creator>Mike DiRenzo</dc:creator>
		<pubDate>Thu, 18 Oct 2007 19:22:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.gavaghan.org/blog/2007/07/17/use-inotifypropertychanged-with-bindinglist/#comment-67</guid>
		<description>Mike:

I posted a reply to your Code Project article about how the events become decoupled during ser/deser process.  After reading this article, My Code Project reply should probably be deleted.  My reply dealt with the &quot;dirtiness&quot; of properties and how to handle them.

Using the technique described above (INotifyPropertyChanged, how would I go about marshalling changes to a data store?  For example, using my technique, I have three extra inherited boolean properties for every class: IsDirty, IsDeleted, IsNew.  I set these props in every other property defined in my class in the setter.  So, if any property changes, the class&#039;s IsDirty property is set to TRUE.  If I add a new object/class to my collection (List), I set the class&#039;s IsNew property to TRUE - same holds true for deletions.  I can send the entire List to a data class method and iterate through it and examine the properties and take appropriate CRUD action.

I am earnestly looking for a better approach.  If you have time, please respond.

-Mike DiRenzo
mike_direnzo@hotmail.com</description>
		<content:encoded><![CDATA[<p>Mike:</p>
<p>I posted a reply to your Code Project article about how the events become decoupled during ser/deser process.  After reading this article, My Code Project reply should probably be deleted.  My reply dealt with the &#8220;dirtiness&#8221; of properties and how to handle them.</p>
<p>Using the technique described above (INotifyPropertyChanged, how would I go about marshalling changes to a data store?  For example, using my technique, I have three extra inherited boolean properties for every class: IsDirty, IsDeleted, IsNew.  I set these props in every other property defined in my class in the setter.  So, if any property changes, the class&#8217;s IsDirty property is set to TRUE.  If I add a new object/class to my collection (List), I set the class&#8217;s IsNew property to TRUE &#8211; same holds true for deletions.  I can send the entire List to a data class method and iterate through it and examine the properties and take appropriate CRUD action.</p>
<p>I am earnestly looking for a better approach.  If you have time, please respond.</p>
<p>-Mike DiRenzo<br />
<a href="mailto:mike_direnzo@hotmail.com">mike_direnzo@hotmail.com</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

