title: PropertyGrid readonly property on object-level
body: <p>I want to display multiple instances of one class in my <code>PropertyGrid</code>. The class looks like this:</p>
  
  <pre><code>public class Parameter
  {
      [Description("the name")]
      public string Name { get; set; }
  
      [Description("the value"), ReadOnly(true)]
      public string Value { get; set; }
  
      [Description("the description")]
      public string Description { get; set; }
  }
  </code></pre>
  
  <p>I have many instances of that class in a <code>TreeView</code>. When I select one of them in my <code>TreeView</code>, the properties show up in the <code>PropertyGrid</code> as expected. So far so good, but I want to customise this behaviour in the following way:</p>
  
  <p>For each single instance I want to be able to prevent the user from modifying a specific property. By setting <code>ReadOnly(true)</code> within my class (as you can see in the example above), all <code>Value</code> properties will be disabled on a <em>class-level</em>.</p>
  
  <p>After some research I found the following solution which gives me the opportunity to enable/disable a specific property at runtime:</p>
  
  <pre><code>PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this)["Value"];
  
  ReadOnlyAttribute attr = 
          (ReadOnlyAttribute)descriptor.Attributes[typeof(ReadOnlyAttribute)];
  
  FieldInfo isReadOnly = attr.GetType().GetField(
          "isReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
  
  isReadOnly.SetValue(attr, false);
  </code></pre>
  
  <p>This approach works just fine but unfortunately also on class-level only. This means if I set the <code>Value</code>'s <code>isReadOnly</code> to <code>false</code>, <em>all</em> of my <code>Parameter</code>-objects have the <code>Value</code> property writeable. But I want this ONLY on that one particular object (thus <em>object-level</em>). I really don't want to create separate classes for read/write and readonly properties.</p>
  
  <p>As I am running out of ideas, your help is much appreciated :)</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT: I need the readonly properties to be grayed-out, so the user can see that it's not allowed or possible to edit them.</p>