Search

Treeview.Sort() does not work properly when when it has a user defined TreeViewNodeSorter. by Milton Xiong

Active

3
0
Sign in
to vote
Type: Bug
ID: 780875
Opened: 3/6/2013 6:02:58 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
TreeView change the order even if comparer returns 0. There are some implementation flaw in Treeview.Sort().
Actually what I want to find out is, how the return value (-1, 0 and 1) of IComparer.Compare() impacts the behavior of method sort().
I did some experiments in my simple application, and found out:
If IComparer.Compare() returns -1, whenever I click the sort button, the nodes order changes - ascending and descending alternatively.
If IComparer.Compare() returns 1, whenever I click the sort button, the nodes order does not change- it keeps the original order.
They make sense. How about IComparer.Compare() returns 0?
I thought it should be same as returning 1. but unfortunately it behaves like returning -1. Return 0 means TreeNode1 has the same sort value as TreeNode2, the original order should not be changed.
Below is the original post, but nobody can give me a good answer:
http://social.msdn.microsoft.com/forums/en-us/winforms/thread/4c6ac5df-6041-434b-aaf7-f5a2fbfc3e48
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

.NET Framework 4.0

Steps to reproduce


Below is the screenshot of a simple winform application.

Here is the source code:
namespace TreeViewSortTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //treeView1.TreeViewNodeSorter = new MySorter();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            treeView1.Sort();
        }

        private class MySorter : IComparer
        {
            public int Compare(object x, object y)
            {
                return 0;
            }
        }
    }
}
No matter how many times I hit the sort button, the nodes order keep unchanged. it is ascending. This is the default sorter's behavior (TreeViewNodeSorter == null)
But if I uncomment this line :
//treeView1.TreeViewNodeSorter = new MySorter();
whenever I click the sort button, the nodes order changes - ascending and descending alternatively.
For more detailed steps, please visit:
http://social.msdn.microsoft.com/forums/en-us/winforms/thread/4c6ac5df-6041-434b-aaf7-f5a2fbfc3e48

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

TreeView.Sort() changes TreeView Nodes original order even the TreeViewNodeSorter returns 0.

Expected results

TreeView Nodes original order should remain unchanged in TreeView.Sort() when the TreeViewNodeSorter returns 0.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 4/18/2013 at 11:18 AM
Hi Milton -

We apologize for the error in our process. This bug should not have been resolved as a duplicate of itself.

We have evaluated the issue that you have reported and at this point in the product's lifecycle, it does not meet the criteria to be addressed. This evaluation is carefully done and considers many aspects including the cost of the fix, implications of the change, and the number of reported instances of the issue.


Many customers have found it useful to discuss issues like this in the forums (http://social.msdn.microsoft.com/forums/en-US/winforms) where Microsoft and other members of the community can recommend ways of achieving the behavior you are interested in.

Thank you,
The Windows Forms Product Team
Posted by Milton Xiong on 3/12/2013 at 6:42 PM
Hi, I don't understand. is it a duplicate of itself?
This issue is a duplicate of 780875? 780875 is itself!
Posted by Microsoft on 3/12/2013 at 4:02 PM
Hi Milton,

This issue is a duplicate of 780875:
http://connect.microsoft.com/VisualStudio/feedback/details/780875/treeview-sort-does-not-work-properly-when-when-it-has-a-user-defined-treeviewnodesorter

Please follow that thread for further updates or workaround suggestions. 

Please keep the feedback coming.
The Windows Forms Product Team
Posted by Microsoft on 3/11/2013 at 12:02 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 3/8/2013 at 10:52 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.