I have a class that I am viewing with a property grid with the following property:
private Color _borderColor = Color.Black;
[Browsable(true)]
[Category("Appearance")]
[DisplayName("Border Color")]
[Description("The color of the border.")]
[DefaultValue(typeof(Color), "Black")]
public virtual Color BorderColor
{
get
{
return _borderColor;
}
set
{
if (_borderColor != value)
{
_borderColor = value;
Invalidate();
}
}
}
I am having various intermittent problems changing this property using the property grid.
Initially, I am able to open the drop-down popup. But when I pick a color it doesn't change the property. When debugging, it does not even call the "set" accessor. At this point, even if I type in the name of the color and press Enter, it doesn't change.
If I deselect the object (which sets the property grid's selecteditem to null), then re-select the object, I am then able to change the color by typing in its name. But the popup still does not work.
Sometimes it bugs out and the popup won't even open when you click the dropdown arrow.
EDIT:
It's specifically a problem with the popup. If I don't use the popup, I don't get any glitches. Opening the popup basically suspends the change being committed (sending a PropertyChanged event) until the entire control loses focus. So once I click on another window or another focusable control, the property grid updates the change.
The question is: why does double clicking or pressing enter cause a change commit, but clicking an item in the popup doesn't?
I figured out what is causing the issue. I have set the window style WS_EX_COMPOSITED on one of the property grid's parents. Disabling this style results in the PropertyGrid functioning normally again.
Unfortunately I need this style to reduce flickering in my application. So I will most likely have to use something other than a PropertyGrid to change my object's properties.