Note that there are some explanatory texts on larger screens.

plurals
  1. POInvalidOperationException while sorting an ObservableCollection
    primarykey
    data
    text
    <p>In my program I have <code>TreeView</code> nodes that I need to be able to shift up and down, basically change the order. My <code>TreeView</code> is an <code>ObservableCollection</code> of a specific Data Model. Each node has a property called "Rank", this is the value that I would like to sort the collection by. With that being said I referred to <a href="https://stackoverflow.com/questions/1945461/how-do-i-sort-an-observable-collection">this question</a>. From that question I discovered this <a href="http://kiwigis.blogspot.com/2010/03/how-to-sort-obversablecollection.html" rel="nofollow noreferrer">blog page</a>. I am attempting the second method involving the <code>sort</code> function of a <code>List</code>.</p> <p>This is the example that I am looking at:</p> <pre><code>List&lt;Person&gt; list = new List&lt;Person&gt;(people); list.Sort(); </code></pre> <p>Please note that the "Rank" value of each node is in working order and changing correctly. I just need to find a way to re-order the collection based off of that property and reflect it in the View.</p> <p><strong>My Problem:</strong> When trying to implement the above solution I get an <code>InvalidOperationException</code>. I feel like I do not understand how to tell the <code>List</code> to sort based off of rank.</p> <p>What my code looks like:</p> <pre><code>List&lt;TreeModel&gt; sortedTree = new List&lt;TreeModel&gt;(TreeCollection); sortedTree.Sort(); </code></pre> <p>What am I missing here? How do I sort the collection based off of the rank property and reflect those changes in the view?</p> <p>Thank you.</p> <p>*I believe I may have posted about this before, so if for some reason this question is too similar my older one, I'll just delete the old one.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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