Question

I have a property grid that helps me manage all of the controls on a form. These controls are for designer-type folks, so I'm not really worried that much about the user interface... until someone selects multiple objects.

I have a UITypeEditor for the "EffectiveDiameter" property on these common objects. It keeps track of units (meters vs feet) and does some nice things on-the-fly. However, when someone selects two or three common objects, EffectiveDiameter is blank, even though it evaluates to the same text string.

For example, in most controls, Microsoft has the "Anchor" property that has a text output of "Top, Right". When you pull it down it is an object with a nice UITypeEditor. Yet, when you select five objects on your form that all have the same Anchor setting you can still see the string "Top, Right" in the property grid.

/// <summary>
/// The default containing class for all Unit-Management Conversion classes.
/// </summary>
[
 Serializable,
 EditorAttribute(typeof(umConversionTypeEditor), typeof(UITypeEditor)),
 TypeConverter(typeof(umConversionTypeConverter)),
]
public class umConversion
{
    ...
}


public class umConversionTypeEditor : UITypeEditor
{
    ...
}



// Now, in my designer class, I have ...
private double _effectiveDiameter { get; set; }

[DisplayName("Effective Diameter")]
public virtual umConversion EffectiveDiameter
{
    get
    {
            umConversion ret = new umConversion (_effectiveDiameter);
            ret.MeasureInSI = _si;
            return ret;
        }
        set
        {
           _effectiveDiameter = value.ImperialUnits;
        }
    }
}

If I select several of my custom objects -- all with the same effective diameter -- how do I get EffectiveDiameter to display in the PropertyGrid like Anchor does? Right now, that field is always blank.

Was it helpful?

Solution

From your description it seems you are talking about the effectiveDiameter of type double. But in your sample you are showing a UITypeEditor for the umConversion class. So, please clarify.

If you are in the second case, where your property is actually a class of your own and not a primitive type, then ensure to implement the Equals method. The MultiPropertyDescriptorGridEntry class in the MS PropertyGrid calls Equals to know if all target instances have the same value. Not sure if this is your problem, but I would test that to eliminate this possibility.

OTHER TIPS

Place a TypeConverter attribute on each property too..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top