Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Is there a known problem with the RefreshPropertiesAttribute not being able to force PropertyGrid to refresh?

I have a simple form that contains a PropertyGrid. I create an object, and give it to PropertyGrid.SelectedObject. I see the properties of that object displayed.

I then click a test button that causes the value of one of the object's properties to change. However, the PropertyGrid does not refresh to display the new value. Only when I click on the grid cell for that property does it refresh.

I decorated the property with the RefreshPropertiesAttribute as follows, but it has no effect.

C#
public class Foo
{
  private bool m_Flag;

  [RefreshProperties( RefreshProperties.All )]
  public bool Flag
  {
    get { return m_Flag; }
    set { m_Flag = value; }
  }
}


I created my own CustomPropertyGrid class that derives from PropertyGrid and overrode Refresh(). Thus, I am certain that Refresh() is not being called.

C#
public class CustomPropertyGrid : System.Windows.Forms.PropertyGrid
{
  public override void Refresh( )
  {
    base.Refresh();
    Debug.WriteLine( "*** Refresh ***" );
  }
}


My development environment is:
- Visual Studio 2008
- Target Framework = .NET 2.0

Any suggestions are appreciated.
Posted
Updated 27-Aug-10 7:52am
v3

1 solution

I realize now that the RefreshPropertiesAttribute only has an effect when the PropertyGrid changes the value of a property in my object.

The solution to my problem is to:
1. Have my object implement an interface that raises a special event when one of its properties changes. For example, INotifyPropertyChanged is a standard one provided by the DotNet framework.

2. Create a derived PropertyGrid that handles that special event from the objects assigned to PropertyGrid.SelectedObjects.

3. In that handler, call PropertyGrid.Refresh().
 
Share this answer
 
Comments
Manfred Rudolf Bihy 23-May-11 19:01pm    
I'm not quite sure why nobdy picked up your question, but great that you came back with your own solution to this. Have my 5!

Proposed as the solution!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900