Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You really shouldn't use code that you don't understand... that's the problem with using bits of code that you find on the internet.</p> <p>If you look in the <code>CreateHeader</code> method you will see that the header titles come from the line:</p> <pre><code>PropertyInfo[] headerInfo = typeof(T).GetProperties(); </code></pre> <p>This is just iterating through the properties defined in your class and bear no relevance to your sorted data. To fix your problem the easy way, just re-order the <code>headerInfo</code> variable to match your sorted data.</p> <p>However, I would recommend that you fix your problem the more difficult way of <em>learning what your code is doing</em> and then adjusting it to your requirements.</p> <p>UPDATE >>></p> <p>After seeing that you are iterating through your <code>DataGrid.ItemsSource</code> collection, I'm guessing that that is your problem, as that collection will remain unchanged after being sorted in the UI. You have a few choices... one method is to update the actual collection that is bound to the <code>ItemsSource</code> property in response to the users' clicks on the various headers in the grid - that way, your current data extraction method would work.</p> <p>Maybe a more common method to use would be to use a <code>CollectionViewSource</code> object <em>between</em> your collection and the <code>DataGrid.ItemsSource</code>... see the <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.collectionviewsource.aspx" rel="nofollow"><code>CollectionViewSource</code> Class</a> page on MSDN for help with this including XAML examples. Basically, when using this method, you can get a copy of the collection <em>in its sorted (and filtered) state</em> from the <code>CollectionViewSource</code> object.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload