[Mono-winforms-list] TreeView.TreeViewNodeSorter seem to have no effect

Carlos Alberto Cortez calberto.cortez at gmail.com
Sat Apr 17 21:16:24 EDT 2010


Hey!

This should be fixed in rev 155655 (svn).

Thanks,
Carlos.

2010/3/24 Latif Khalifa <latifer at radegastclient.org>

> I finally managed to figure out under what circumstances the bug
> shows. I have a single root node, creatively labeled "root". In that
> case TreeView ignores the sorter and sorts alphabetically. Here is my
> simple Compare() that is supposed to sort nodes in reverse
> alphabetical order:
>
>    public class SorterClass : System.Collections.IComparer
>    {
>        public int Compare(object a, object b)
>        {
>            int res = string.Compare(((TreeNode)a).Text,
> ((TreeNode)b).Text);
>            res *= -1;
>            return res;
>        }
>    }
>
> And here is a short example that creates TreeView:
>
>            invTree = new TreeView();
>            invTree.Dock = DockStyle.Fill;
>            invTree.TreeViewNodeSorter = new SorterClass();
>            Controls.Add(invTree);
>
>            TreeNode root = new TreeNode("My root");
>            invTree.Nodes.Add(root);
>
>            for (char c = 'A'; c <= 'Z'; c++)
>            {
>                TreeNode n = new TreeNode();
>                n.Text = c.ToString();
>                n.Name = c.ToString();
>                for (int i=0; i<20; i++)
>                {
>                    TreeNode inside = new TreeNode(i.ToString());
>                    n.Nodes.Add(inside);
>                }
>                root.Nodes.Add(n);
>            }
>
>            invTree.Sort();
>
> Two observed behaviors differ from .net
>
> 1) Bug, Setting TreeViewNodeSorter has no effect if there is only one
> top level node. (actually it does have an effect of turning on
> sorting, just that the Compare() is never called and sorting is done
> by a default system function).
> 2) Different behavior. On Windows under .NET one does not need to
> explicitly call Sort(). Nodes are sorted as they are inserted.
>
> Latif
>
> On Tue, Mar 23, 2010 at 7:03 PM, Carlos Alberto Cortez
> <calberto.cortez at gmail.com> wrote:
> > Hey!
> > I tested this on those same versions, and I cannot get the error. Could
> you
> > cook a small test case?
> > Carlos.
> >
> > 2010/3/23 Latif Khalifa <latifer at radegastclient.org>
> >>
> >> Hello,
> >>
> >> I have had this problem with both 2.4.2.3 and 2.6.3. Identical code
> >> works on .net side, in mono's TreeView sorting is always alphabetic
> >> and my Compare() never gets called.
> >>
> >> Latif
> >>
> >>
> >> On Tue, Mar 23, 2010 at 4:00 PM, Carlos Alberto Cortez
> >> <calberto.cortez at gmail.com> wrote:
> >> > Hey,
> >> > This should be working. Maybe you hit a bug, but it seems, based on
> the
> >> > other information, that you are using an old version. Take a look at
> >> > that
> >> > and let us know.
> >> > Carlos.
> >> >
> >> > 2010/3/23 Latif Khalifa <latifer at radegastclient.org>
> >> >>
> >> >> Hi,
> >> >>
> >> >> I'm trying to cure a few last quirks an an application I'm porting
> >> >> from windows. The problem I'm having is that setting
> >> >> TreeView.TreeViewNodeSorter seem to have no effect. The nodes gets
> >> >> sorted alphabetically and Compare() in my IComparer class never gets
> >> >> called. Any ideas?
> >> >>
> >> >> Also TreeView seem to be missing [+] and [-] images next to the nodes
> >> >> that can be expanded and collapsed.
> >> >>
> >> >> Latif
> >> >> _______________________________________________
> >> >> Mono-winforms-list maillist  -  Mono-winforms-list at lists.ximian.com
> >> >> http://lists.ximian.com/mailman/listinfo/mono-winforms-list
> >> >
> >> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20100418/6dca671b/attachment-0001.html 


More information about the Mono-winforms-list mailing list