Disabling dynamic properties in grid based on dynamic checkbox

Grids for WPF Forum

Posted 8 years ago by Mick
Version: 13.1.0582
Avatar

I am trying to disable or make read only some properties at run time based on when a check box is checked and I'm having some trouble figuring out the best way to accomplish this. My SelectedObjects is bound to a large main Object, call it mainObj. Inside mainObj there is a smaller object, called subObj. Inside subObj is the checkbox property. 

When this checkbox property is checked, I want to disable all other properties in subObj only except for the one checkbox while not touching any of the properties in mainObj. The main problem I am seeing is all of the properties are being generated dynamically using attributes on the property names. There is no xaml for these properties, there is just the one control that creates the PropertyGrid.

Is there a good way to accomplish this?

Comments (5)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mick,

Have you seen the "Selective Read-Only" QuickStart in the Sample Browser?  That shows one way that you can make certain properties read-only, but a custom data factory is required.


Actipro Software Support

Posted 8 years ago by Mick
Avatar

I see that in the sample browser which looks like what I'm trying to accomplish but I don't see any code or examples associated with it. It just gives me a brief description that using a custom data factory allows me to update properties. But I am unable to find any information on this custom data factory or how to set it up.

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mick,

The full source for the Sample Browser project is included.  Once you open the project, it's all in this relative folder:

\ProductSamples\PropertyGridSamples\QuickStart\SelectiveReadOnly\


Actipro Software Support

Posted 8 years ago by Mick
Avatar

Ok I believe I was able to get most of this working. Looking at the example the test object is inheriting from the ObservableObjectBase class. I was unable to inherit this class as it was erroring out with our nHibernate setup that we are using. It was basically complaining about some methods not being virtual in a class that I do not have access to.

I was able to get around this by manually calling the Refresh method on the property grid in my custom propertyDescriptorDataAccessor class' onValueChanged method. But I feel like this is not the best place for calling this refresh as it hits this method quite a bit and this causes the update to be a bit slow.

Are there any recommendations on how else I can refresh this grid when the property changes?

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mick,

ObservableObjectBase is just a utility class that implements INotifyPropertyChanged.  You could use any base class (you may have one in your own code) that implements that interface since PropertyGrid watches that to know when a value changes.  That is what I'd recommend.


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.