views:

58

answers:

1

Hey guys,

We have an object that is assigned to a PropertyGrid using the SelectedObject property of the PropertyGrid. This object contains a few properties which get updated by code in various places. For the purpose of this example, assume one is a simple update (ie: caused by the following code - Person.FirstName = "Gareth"), and that another is a bit more complex; a duration from a start time (ie: Person.AgeInSeconds).

Does anyone know what the simplest method is to have the value of these property updated automatically in a PropertyGrid, when the value of the properties change?

Thanks in advance,

Nick

A: 

Try adding the INotifyPropertyChanged interface to your object and then raising the event when a property is updated in the setter. I am not sure if the PropertyGrid looks for and listens to this interface but it is worth a try.

If not you can always do this yourself. So each time you assign to SelectedObject you hook the INotifyPropertyChanged interface update event and whenever fire you get the PropertyGrid to refresh. When it is removed from SelectedObject you remove the event hook.

Phil Wright