title: WPF ListView - Sorting by Nested Properties
body: <p>I have recently stumbled across an issue where the WPF <code>ListView</code> control seems to be restricting the ability to sort its items. Specifically, I am having a great deal of trouble trying to get a <code>SortDescription</code> to recognise nested properties (properties of properties).</p>
  
  <p>For straight-forward sorting by propreties, the following line should do the job:</p>
  
  <pre><code>listView.Items.SortDescriptions.Add(new SortDescription("MyProperty",
      ListSortDirection.Ascending));
  </code></pre>
  
  <p>And indeed it works well for me. However, because the <code>ItemSource</code> for my <code>ListView</code> is a (strongly-typed) <code>DataTable</code>, some of the columns are bound to nested properties of the row (i.e. <code>Row.OtherTableRow.SubProperty</code> binding path style) - it's the way ADO.NET DataSets work for hierarchial databases.</p>
  
  <p>What I would like to do is something like this:</p>
  
  <pre><code>listView.Items.SortDescriptions.Add(new SortDescription("MyProperty.SubProperty",
      ListSortDirection.Ascending));
  </code></pre>
  
  <p>But unfortunately that line throws an <code>ArgumentException</code>:</p>
  
  <blockquote>
    <p>'Orders' type does not have property named 'Row.[ID]', so cannot sort data collection.</p>
  </blockquote>
  
  <p>Strangely enough, I have no problem binding to nested properties. Indeed, the fields display perfectly well in the <code>ListView</code>... Nor does adding a <code>PropertyGroupDescription</code> to <code>listView.GroupDescriptions</code> give me any problems with nested properties - it is only <code>SortDescriptions</code>!</p>
  
  <p>Is this but a limitation of WPF/the <code>ListView</code> control? Is there any way I'm going to get support as part of the framework, or will I be out of luck there? If I unfortunately am, and this inconsistency is unavoidable, I would much appreciate if someone could suggest a hack or workaround for this scenario of nested properties. I have tried a few ideas already, but all with minimal success.</p>
  
  <p>Note: I realise that an ORM may well solve my problems, but I'm afraid this isn't at all feasible for the current project I'm working on. Simple ADO.NET DataSets will have to do.</p>