Changing the list of properties w/o changing SelectedObjects

Grids for WPF Forum

Posted 9 years ago by Nate Hekman
Version: 10.1.0522
Avatar
I am using SelectedObjects to populate my grid, and using a ICustomTypeDescriptor to provide the list of properties (which are all PropertyDescriptors).

One of the properties of my object actually changes the object's collection of properties--the ICustomTypeDescriptor.GetProperties() will return a different list of properties. How can the ICustomTypeDescriptor signal to the grid to re-call GetProperties and update itself?

Or am I going down the wrong trail? I've just re-read the documentation and am thinking of a couple of other options:
  • Filters: Perhaps I could return all properties all the time, but use a filter to hide the ones I don't want displayed, based on the value of the one property that controls the list?
  • Custom DataFactory: I don't think this will help, as I'm already able to use the ICustomTypeDescriptor.GetProperties to return the correct list of properties, and the DataFactory doesn't appear to provide any additional means of indicating that the list has changed.
Can you give me any suggestions to set me down the right path?

Thank you!

Nate

Comments (7)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nate,

There's nothing "built-in" to refresh the PropertyGrid from the object, which it's exposed properties change. The PropertyGrid does have a Refresh method that you can call, but you'd have to manually call it.

When you are talking about sub-properties (i.e. properties of properties) there are some other mechanisims available, but I'm not sure that applies in this case.


Actipro Software Support

Posted 9 years ago by Nate Hekman
Avatar
Bummer. I'll see what I can do about calling Refresh directly.

I have sub-properties updating in this way already, but just got stuck on the root properties.

Consider this a feature request then. :-)
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nate,

For sub-properties, you can actually leverage NotifyParentPropertyAttribute. If this is set to true on a sub-property, then it's parent property will be refreshed anytime the sub-property's value is changed. Not sure if this applies in your case though.

I've marked down your feature request on our TODO list. How would you expect this to work?

The correct way would probably be to add a known interface/attribute that you'd use in your class. The problem with this approach is most developers would not want to link our PropertyGrid assembly to their "data" assemblies, which means we probably can't define the known interface/attribute.

We could also leverage existing .NET interfaces/attributes, like INotifyPropertyChanged with PropertyName set to "" or NotifyParentPropertyAttribute, but that would not really be in the scope of what those types were designed to do.


Actipro Software Support

Posted 9 years ago by Nate Hekman
Avatar
I see your point. I guess the problem comes down to the fact that there's no built-in .NET way of indicating that a CustomTypeDescriptor has changed. I've got this (mostly) working now in my code by adding my own INotifyCustomTypeDescriptorChanged, but I can see how that's not an interface you could provide without forcing us to reference your libraries in our data layer.

I've been reading up today on dynamic objects in .NET 4, and that looks very promising. That's essentially what I have, is a dynamic object, whose list of properties changes at runtime. I don't have time to start over implementing it this way, but I think that would be the ideal, for the grid to support "dynamic" as a valid type for SelectedObjects. Look up ExpandoObject on msdn for example (or IDynamicMetaObjectProvider)--this object type will raise events as its list of properties changes.

For now I'm going to try to get by with calling PropertyGrid.Refresh when my property list changes. That's pretty extreme though: the grid loses track of which cell had focus, which categories or tree nodes were expanded/collapsed, etc. All that has really changed in the object is that it has added or removed a couple of properties, but the grid acts as if an entirely new object got selected.
Posted 9 years ago by Luke W
Avatar
I ran into this exact issue today. Since this thread is somewhat stale, I was interested if there had been any more thought to this problem by either Actipro, or if the submitter still receives notifications from this thread, I'm curious to his solution.
Posted 9 years ago by Nate Hekman
Avatar
I ended up sticking with the last idea I mentioned, calling PropertyGrid.Refresh. It's not a great solution, as I described, but it was good enough to let me move on. I still intend to go back and see what I can do to make it work more smoothly (remembering the last cell with focus and re-setting it, for example), but I got pulled off to another project and haven't actually looked at it in a few months.
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi All,

We have a new sample, which will be included in the next maintenance release, that shows how to change the visiblity of properties based on the values of other sibling properties. Unlike what is discussed above though, all the properties are passed to the PropertyGrid (i.e. no filtering is done by the ICustomTypeDescriptor) and their Visibility is updated dynamically. This avoids the need to call Refresh, as we can simply toggle the Visibility property.

If you'd like a copy of this sample before it's release, please send a request to our support address.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.