How to force the grid to re-read values from UI

Grids for WPF Forum

Posted 7 years ago by Tony Juricic
Version: 11.2.0552
Avatar

I have a grid looking at the object having 3 nullable integer properties. Of these three, two properties should be treated as exclusive: if one has a value, the other can't have a value. In my current UI I get 3 edit boxes with checkboxes for nullable value.

Of course, since I haven't done anything custom so far, when I uncheck not-nullable checkbox of one property, and thus make it have no value, the other property doesn't get checked automatically and thus acquire a default value.

I am not sure how to get this behavior, particularly because, for various reasons, I can't change the original object so that I don't have two exclusive nullable integer properties and I can not add INotifyPropertyChanged.

As for the title of this question, it should have been reversed. I want to update target from the source. I think I could solve the problem described without a custom editor, if, when I get Change notification for a property, I could read and change the state of grid editor UI elements. Like, if I could read if nullable checkbox is set for a particular property and if not, then set it. 

[Modified 7 years ago]

Comments (1)

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

Hi Tony,

There are several ways that this could be accomplished, so it really depends on your needs. Some possible solutions are:

1. You could create an object that "wraps" your original object, and then assign that object to the PropertyGrid. This can be done a few ways, such as creating an object with the same properties and simply calling into the wrapped object. Alternatively, you could implement ICustomTypeDescriptor, which will be more dynamic. In both cases, you'd need special handling to ensure the two properties are mutually exclusive. This solution is independent of our PropertyGrid.

2. You could create a custom DataFactory and IPropertyDataAccessors, which contain the logic needed. This is specific to our PropertyGrid, but is independent of the UI portion.

3. Create custom property editors can contain the logic. You could setup bindings from the CheckBox to both properties (using an attached behavior/property), then map that editor to the two properties in question.

4. You could handle the PropertyGrid.PropertyChanged event and look for the two properties in question.

If you need more information on any of these approaches, please let us know.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 10 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.