title: Sorting Datagridview datasource on List<T> where T is anonymous
body: <p>A relatively simple question.  I have a datagridview, which all it does is displays statistics.  There is no editing/adding/deleting of rows.  The datagridview is bound to a List.  All I want to achieve is to have the user be able to sort the columns.</p>
  
  <pre><code>class Market
  {
      public int Location {get;set;}
      public float Value {get;set;}
      //...
  }
  class City
  {
      public String Name {get;set;}
      //...
  }
  
  List&lt;Market&gt; _markets;
  List&lt;City&gt; _cities;
  //Lists are populated.
  
  dataGridView1.DataSource = _markets.Select(market =&gt; 
      new { _cities[market.Location].Name, market.Value}).ToList();
  </code></pre>
  
  <p>As expected, the columns are not sortable, but the information that is displayed is what is wanted.  My question is how to make the DataGridView sort based on the column type with the least complicated and least amount of code, as the code will be used multiple times throughout.</p>
  
  <p>This application used to use a DataBase that had views.  These views then populated the DataGridViews.  The views are still around, so a possible solution could be:</p>
  
  <pre><code>DataBase.ViewMarketValue temp = new DataBase.ViewMarketValue()
  
  _markets.ForEach(market =&gt; temp.AddViewMarketValueRow(_cities[market.Location].Name, market.Value);
  dataGridView1.DataSource = temp;
  </code></pre>
  
  <p>This results in the desired: a datagridview that has all the information and it is sortable.  The only problem is that it seems wrong to use views in this aspect.  So what should I do?</p>