TreeListBox list addition does not trigger custom sorting

Grids for WPF Forum

Posted 3 years ago by Sunshine - Appeon
Version: 21.1.1
Avatar

Example : https://ibb.co/x7GqBGp

I inherited TreeListBoxItemAdapter and overridden the GetChildren method.

This is my code:

public override IEnumerable GetChildren(TreeListBox ownerControl, object item)
        {
            if (item is TreeNode node)
            {
                if (this.IsAutoSorted)
                {
                    var collection = CollectionViewSource.GetDefaultView(node.Children);

                    collection.SortDescriptions.Add(new SortDescription("Order", ListSortDirection.Ascending));

                    collection.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

                    return collection;
                }
                else
                {
                    return node.Children;
                }
            }
            else
            {
                return Enumerable.Empty<ITreeNode>();
            }
        }

I sort the collection according to Order and Name.

When I add a node, the tree cannot automatically trigger my sorting rules.

I collaspse and then expand, it can trigger the sorting rules.

How to solve this problem so that the sorting is triggered correctly when adding nodes?

Thanks!

Comments (7)

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

GetChildren is only called when the node is requesting its children for expansion.  Once a node is expanded, it watches the collection returned from GetChildren to see if it notifies of any changes.  If it does, TreeListBox will try and make the appropriate insertion/removal in the same spot indicated by INotifyCollectionChanged.  

Can you watch the view and attach to its CollectionChanged property here to see which index it says to insert the item?  That is effectively the index we use to determine where the inserted node goes.  See if it's the same as what you see resulting in the UI.  I would think that the collection view would insert the new item into a sorted location and that its CollectionChanged event would point to that new sorted index.


Actipro Software Support

Posted 3 years ago by Sunshine - Appeon
Avatar

I can see the index of the inserted item and the sorting in the collection by subscribing to the CollectionChanged event. I found that the sorting in the collection and the inserted index are correct, but the UI display is inconsistent.

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Ok, in that case, can you reproduce this in a new simple sample project and send that over to our support address?  Please mention this thread in your e-mail and remove the bin/obj folders from the .zip you send so it doesn't get spam blocked.  Then we'll debug with that to see what's happening.  Thanks!


Actipro Software Support

Posted 3 years ago by Sunshine - Appeon
Avatar

The demo project and video will be sent to your email shortly.

Due to the actual situation, our project scene is very complicated and cannot be fully reproduced in the demo project, but we found that the "IsExpanded" property setting on the node will cause the phenomenon we see. When I added a node, I controlled its parent node to collapse  and then expand. As a result, the phenomenon in the demo video appeared.

This may be helpful in tracking down such issues.

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

We haven't received any emails, so if you sent it already, it may have been spam blocked.  Please make sure all bin/obj folders are removed from the .zip you send.  Or you can go to our ticket system and create a ticket directly there without email.


Actipro Software Support

Posted 3 years ago by Sunshine - Appeon
Avatar

Hi!

Have you received our case? Our colleagues sent the case to your mailbox on the morning of September 6th, China time.

Looking forward to your reply, thank you!

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Yes we wrote you a reply first thing on September 7.  If you log into the ticket system, you should see our reply.  You also should have gotten an email when we sent it.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.