Ticket T1285799
Visible to All Users

Perform a sort on two or more columns programmatically

created 6 days ago

Hello,
I'm using the TreeList.Sort method to manually sort only certain nodes of a TreeList based on certain actions the end-user does. This system works perfectly when trying to sort a single column, but what if I need to sort by two or more columns? Like when you sort the TreeList by pressing Shift and clicking different column headers, I would like to sort my tree based on the values of two or more different columns programmatically. Is there a way to achieve this?

Thank you,
Daniele

Answers approved by DevExpress Support

created 3 days ago

Hello Daniele,

If you need to sort all nodes in your TreeList, I recommend that you specify the column's SortOrder and SortIndex properties. The SortIndex property determines the order of columns that will be used to sort the nodes. For more information, please refer to the following help topic: Sorting via Code.

Otherwise, if you need to sort only particular nodes, then you need to create a custom IComparer class that takes into account the values from multiple columns and pass an instance of it to the TreeList.Sort method. You can refer to the following StackOverflow thread for an example: IComparer on multiple values.

Should you have additional questions, let me know.

    Comments (1)
    DT DT
    Daniele Talignani 3 days ago

      Hi Christian,
      since I need to sort only particular nodes, I'll try using a custom IComparer.

      Thank you for your help.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.