PC Review


Reply
Thread Tools Rate Thread

Detecting PropertyChanged events

 
 
=?Utf-8?B?TGFuY2U=?=
Guest
Posts: n/a
 
      30th Mar 2004
I have two classes (lets call them A and B). A and B will always be classes of identical types, although the class type is unknown at design time. What I need to do is update a property of B whenever the same property of A changes (but not update A when B changes). In other words, I need to be able to detect all of the PropertyChanged events of A and then, when an event occurs, set the corresponding property of B equal to the property of A. I imagine that this is similar to how a PropertyGrid monitors its SelectedObject(s)

Thanks for any help
Lance
 
Reply With Quote
 
 
 
 
Bill McCarthy
Guest
Posts: n/a
 
      30th Mar 2004
Hi Lance,

The property grid actually does not automatically refresh. What it does do is
uses an attribute on properties that tells it to refresh if it actually sets the
value. If however, you modify the value elsewhere, that is not automatically
reflected in the property grid.
There are a couple of approaches you can take, such as having the property's
only changeable via your control, or if you can modify the actual types, then
you can raise a PropertyChanged event that can be subscribed to. another pattern
used is the XXXChanged pattern, which you could wire into using reflection.

Bill.






"Lance" <(E-Mail Removed)> wrote in message
news:2CFAED04-25FB-433C-9255-(E-Mail Removed)...
> I have two classes (lets call them A and B). A and B will always be classes

of identical types, although the class type is unknown at design time. What I
need to do is update a property of B whenever the same property of A changes
(but not update A when B changes). In other words, I need to be able to detect
all of the PropertyChanged events of A and then, when an event occurs, set the
corresponding property of B equal to the property of A. I imagine that this is
similar to how a PropertyGrid monitors its SelectedObject(s).
>
> Thanks for any help.
> Lance



 
Reply With Quote
 
Charles Law
Guest
Posts: n/a
 
      30th Mar 2004
Hi Lance

How about ... create an OnPropertyChanged method in class A, which raises an
event PropertyChanged whenever a property is changed, i.e. call it from the
Set method of each property.

When you create class B object, add a handler for the corresponding class A
object for the PropertyChanged event. If you include the property name and
new value in the event args you can update the properties in class B.

HTH

Charles


"Lance" <(E-Mail Removed)> wrote in message
news:2CFAED04-25FB-433C-9255-(E-Mail Removed)...
> I have two classes (lets call them A and B). A and B will always be

classes of identical types, although the class type is unknown at design
time. What I need to do is update a property of B whenever the same
property of A changes (but not update A when B changes). In other words, I
need to be able to detect all of the PropertyChanged events of A and then,
when an event occurs, set the corresponding property of B equal to the
property of A. I imagine that this is similar to how a PropertyGrid
monitors its SelectedObject(s).
>
> Thanks for any help.
> Lance



 
Reply With Quote
 
=?Utf-8?B?TGFuY2U=?=
Guest
Posts: n/a
 
      31st Mar 2004
>you can raise a PropertyChanged event that can be subscribed to. another pattern used is the XXXChanged pattern, which you could wire into using reflection

That sounds possible. Thanks

 
Reply With Quote
 
=?Utf-8?B?TGFuY2U=?=
Guest
Posts: n/a
 
      31st Mar 2004
Thanks for the idea, but I have over 1500 properties so I need something a little more automated.
 
Reply With Quote
 
Peter Huang
Guest
Posts: n/a
 
      31st Mar 2004
Hi Lance,

Based on my understanding, you have two class A and B,(Are the class A and
B you mention is a generic class or a component?), in your code you will
new the two classes and set each of them to a propertygrid. Then if we
change one of the property of A, we will change the according property of B.
If I misunderstand your meaning, please feel free to tell me.

I think if the two classes A and B are generic class(a plain class inherits
from object), to achieve your aim, we have to define an event and raise the
event in every set methods of properties of A but you can write just one
event handler function in the class B.

If the two classes are component, we can use the
IComponentChangeService.ComponentChanged.
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemComponentModelDesignIComponentChangeServiceClassComponentAddedTop
ic.asp


Look for the title in the link below on how to use the
IComponentChangeService.ComponentChanged
53.4 How do I control the state of my custom verb in my designer?
http://www.syncfusion.com/FAQ/WinForms/FAQ_c80c.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting Network Change Events John Wright Microsoft VB .NET 1 1st Oct 2009 12:37 AM
Detecting conflicts with all day events. liyuhua@gmail.com Microsoft Outlook VBA Programming 1 18th Apr 2005 01:11 PM
Detecting form control events from an add-in Errol Limani Microsoft Outlook Program Addins 3 19th Jul 2004 02:48 PM
Detecting Another Application's Events scorpion53061 Microsoft VB .NET 4 14th Feb 2004 09:51 PM
What is the syntax for detecting function key events? Sean Connery Microsoft C# .NET 4 11th Dec 2003 10:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:46 AM.