title: How to set Listbox DisplayMember and ValueMember using fields of an object?
body: <p>I have a few DTOs that I am using which are designed like this:</p>
  
  <pre><code>ProjectPrimitives
     string Name
     int ProjectId
  
  ProjectDetails : ProjectPrimitives
     string ReportName
     string Description
     // Others
  
  Project
     ProjectDetails details
     List&lt;Contact&gt; contacts
     // Some more
  </code></pre>
  
  <p>In my application I have a listbox where I would like to display <code>Project</code> objects. Previously, I was displaying <code>ProjectPrimitives</code> by doing the following:</p>
  
  <pre><code>projectListBox.DisplayMember = "Name";
  projectListBox.ValueMember = "ProjectId";
  projectListBox.DataSource = projects; // This is a List&lt;ProjectPrimitives&gt;
  </code></pre>
  
  <p>However, now that I'm displaying <code>Project</code> objects, I can't get this to work. I've tried:</p>
  
  <pre><code>projectListBox.DisplayMember = "Details.Name";
  projectListBox.ValueMember = "Details.ProjectId";
  projectListBox.DataSource = projects; // This is now a List&lt;Project&gt;
  </code></pre>
  
  <p>But that didn't work. All it does is display the object (<code>MyProject.DTOs.Project</code>). What can I do to display the name?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The ProjectPrimitives class:</p>
  
  <pre><code>public class ProjectPrimitives
  {
     public int ProjectId {get; set;}
     public string Name {get; set;}
  }
  </code></pre>
  
  <p>The Project class:</p>
  
  <pre><code>public class Project
  {
     public ProjectDetails details = new ProjectDetails();
  }
  </code></pre>