This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
when I load an observabledictionary with strings and objects, its loaded as it comes in from an xml file. the grid is then sorting all the properties by alphabet. I want them to stay in the order that they are loaded with. How can I turn the sorting off?
|
|
|
You can't "turn the sorting off" per se: dictionaries in general make no guarantees about what order the objects come out in, and the ObservableDictionary certainly doesn't. We would usually advise performing sorting in the UI by adding a SortDescription to the BindingView.DefaultView. However, looking at your requirement I suspect there isn't going to be a suitable property that you can sort on, so I think we will need to add some functionality to the core product to enable this. I will have a think about this and get back to you. |
|
|
I thought of a way you could get the dictionary sorted in the order you want without needing any changes to the grid itself: 1. Define a new class to act as your key, called e.g. SortableString. Its properties will be SortIndex (integer) and Text (string). 2. Implement IComparable(Of SortableString) on this class. The CompareTo function should return Me.SortIndex - other.SortIndex. 3. Override ToString() on this class. The override should return Me.Text. 4. Change your ItemsSource dictionary to be ObservableDictionary(Of SortableString, Object). As you load the entries from your XML and add them to the dictionary, keep incrementing the SortIndex of the new SortableStrings. (Please excuse any errors in my Visual Basic syntax.) The presence of IComparable will cause the dictionary to return items to the grid in the correct sort order, and the ToString() override will ensure that the entries continue to display the correct names. BONUS FEATURE: With this approach, you can still apply custom sort orders in the UI, and these custom sort orders can access whatever additional data is stuffed into the key. The full key is available to the SortDescription as Node.IndexedPropertyArguments[0]. For example, to display your items in the reverse order of loading from XML (reverting to C# here, sorry): SortDescription sd = new SortDescription("Node.IndexedPropertyArguments[0].SortIndex", ListSortDirection.Descending); I actually prefer this approach to trying to add extensible sort functionality into the core grid (and feel from initial prototyping that any attempt to handle this in the core grid will actually end up being harder to work with), so will leave it at this unless you feel it doesn't meet your requirements. |
|
|
that does the trick, Ivan - amazing... I have to say I have never seen support from a controls vendor like this. I am extremely satisfied with the product and the company and recommending that our company purchase a site license. Thank you very much.
|
|