I have a problem with propertygrid not displaying the parent value of an expandable property for multiple objects (using propertygrid.SelectedObjects)
[Browsable(true), TypeConverter(typeof(ExpandableObjectConverter))]
public class MyNestedClass {
private int a;
private int b;
[Browsable(true),
ReadOnly(false),
RefreshProperties(RefreshProperties.Repaint),
NotifyParentProperty(true)]
public int A {
get { return this.a; }
set { this.a = value; }
}
[Browsable(true),
ReadOnly(false),
RefreshProperties(RefreshProperties.Repaint),
NotifyParentProperty(true)]
public int B {
get { return this.b; }
set { this.b = value; }
}
public MyNestedClass(int a, int b) {
this.a = a;
this.b = b;
}
public override string ToString() {
return this.a.ToString() + “; “ + this.b.ToString();
}
}
This class is part of another class myClass, where myNestedClass is defined as a browsable property within.
public class MyClass {
…
private MyNestedClass myNestedClassObject;
…
[Browsable(true),
ReadOnly(false),
MergableProperty(true),
RefreshProperties(RefreshProperties.Repaint)]
public MyNestedClass MyNestedClassObject {
get { return myNestedClassObject; }
set { myNestedClassObject = value; }
}
…
}
Everything is working fine, when only one instance of class myClass is displayed in the propertygrid.
The propertygrid shows:
…
MyNestedClassObject | 1; 2
A | 1
B | 2
…
In the case I’m trying to display an array of MyClass instances (via propertygrid.SelectedObjects), where myNestedClass objects do have the same values for a and b, I only see something like this in the propertygrid:
…
MyNestedClassObject |
A | 1
B | 2
…
I know that the propertygrid is designed to show only common properties of multiple objects, what’s true for the subproperties a and b. But why the so called “typeconverter” (or parent) line of the expandable properties do have an empty value portion, although the subproperties a and b are the same for all objects?
Can anybody shed a bit of light on that and/or can help me on this issue?
Many thanks in advance
Jochen
After more research on that issue I found the solution thanks to another stackoverflow article:
PropertyGrid mult. controls select, null exception on property set?
The author had the same issue with expandable properties when multiple objects are selected where all properties are common to all instances. The “typeconverter” (or parent) line stayed empty, on the other hand subproperties are shown.
He noticed to override method Equals in the class whose instances are displayed in the property grid.
And yes, that’s it.
Many thanks to greggorob64 !
with kind regards