title: display list of custom objects as a drop-down in the PropertiesGrid
body: <p>I want to take an object, let's say this object:</p>
  
  <pre><code>public class BenchmarkList
  {
      public string ListName { get; set; }
      public IList&lt;Benchmark&gt; Benchmarks { get; set; }
  }
  </code></pre>
  
  <p>and have that object display its ListName as the "name" part of the PropertiesGrid ("Benchmark" would be good), and for the "value" part of the PropertyGrid, to have a drop-down list of the IList&lt;> of Benchmarks:</p>
  
  <p>here is the Benchmark object</p>
  
  <pre><code>public class Benchmark
  {
      public int ID {get; set;}
      public string Name { get; set; }
      public Type Type { get; set; }
  }
  </code></pre>
  
  <p>I would want the drop-down to show the Name property of the Benchmark for what the users can see. Here is a visual example:</p>
  
  <p><img src="https://i.stack.imgur.com/tTq5q.png" alt="enter image description here"></p>
  
  <p>So, essentially, I'm trying to get a collection of Benchmark objects into a drop-down list, and those objects should show their Name property as the value in the drop-down.</p>
  
  <p>I've read other articles on using the PropertiesGrid, including <a href="http://www.codeproject.com/KB/tabs/customizingcollectiondata.aspx#StartGoal" rel="noreferrer">THIS</a> and <a href="http://www.codeproject.com/KB/miscctrl/bending_property.aspx" rel="noreferrer">THIS</a>, but they are more complex than what I'm trying to do.</p>
  
  <p>I usually work on server-side stuff, and don't deal with UI via WebForms or WinForms, so this PropertiesGrid is really taking me for a ride... </p>
  
  <p>I do know my solution lies in implementing "ICustomTypeDescriptor", which will allow me to tell the PropertiesGrid what values it should be displaying regardless of the properties of the object to which I want to bind into the drop-down list, but I'm just not sure how or where to implement it.</p>
  
  <p>Any pointers/help would be much appreciated.</p>
  
  <p>Thanks,
  Mike</p>
  
  <p>UPDATE:</p>
  
  <p>Okay, so I'm changing the details around a little. I was going overboard before with the objects I thought should be involved, so here is my new approach. </p>
  
  <p>I have an object called Analytic. This is the object that should be bound to the PropertiesGrid. Now, if I expose a property that is of an enum type, PropertiesGrid will take care of the drop-down list for me, which is very nice of it. If I expose a property that is a  collection of a custom type, PropertiesGrid is not so nice...</p>
  
  <p>Here is the code for Analytic, the object I want to bind to the PropertiesGrid:</p>
  
  <pre><code>public class Analytic
  { 
      public enum Period { Daily, Monthly, Quarterly, Yearly };
      public Analytic()
      {
          this.Benchmark = new List&lt;IBenchmark&gt;();
      }
      public List&lt;IBenchmark&gt; Benchmark { get; set; }
      public Period Periods { get; set; }
      public void AddBenchmark(IBenchmark benchmark)
      {
          if (!this.Benchmark.Contains(benchmark))
          {
              this.Benchmark.Add(benchmark);
          }
      }
  }
  </code></pre>
  
  <p>Here is a short example of two objects that implement the IBenchmark interface:</p>
  
  <pre><code>public class Vehicle : IBenchmark
  {
      public Vehicle()
      {
          this.ID = "00000000-0000-0000-0000-000000000000";
          this.Type = this.GetType();
          this.Name = "Vehicle Name";
      }
  
      public string ID {get;set;}
      public Type Type {get;set;}
      public string Name {get;set;}
  }
  
  public class PrimaryBenchmark : IBenchmark
  {
      public PrimaryBenchmark()
      {
          this.ID = "PrimaryBenchmark";
          this.Type = this.GetType();
          this.Name = "Primary Benchmark";
      }
  
      public string ID {get;set;}
      public Type Type {get;set;}
      public string Name {get;set;}
  }
  </code></pre>
  
  <p>These two objects will be added to the Analytic object's Benchmark List collection in the WinForms code:</p>
  
  <pre><code>private void Form1_Load(object sender, EventArgs e)
  {
      Analytic analytic = new Analytic();
      analytic.AddBenchmark(new PrimaryBenchmark());
      analytic.AddBenchmark(new Vehicle());
      propertyGrid1.SelectedObject = analytic;
  }
  </code></pre>
  
  <p>Here is a screen-grab of the output in the PropertiesGrid. Note that the property exposed as an enum gets a nice drop-down list with no work, but the property exposed as an of List on gets a value of (Collection). When you click on (Collection), you get the Collection editor and then can see each object, and their respective properties:</p>
  
  <p><img src="https://i.stack.imgur.com/dXs2J.png" alt="enter image description here"></p>
  
  <p>This is not what I'm looking for. Like in my first screen grab in this post, I'm trying to render the property Benchmark collection of List as a drop-down list that shows the object's name property as the text of what can be displayed...</p>
  
  <p>Thanks</p>