Re: TreeView.TreeViewNodeSorter seem to have no effect
Carlos Alberto Cortez <[email protected]>
| Newsgroups | gmane.comp.gnome.winforms |
|---|---|
| Message-ID | <[email protected]> |
Hey! This should be fixed in rev 155655 (svn). Thanks, Carlos. 2010/3/24 Latif Khalifa <[email protected]> > 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 > <[email protected]> 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 <[email protected]> > >> > >> 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 > >> <[email protected]> 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 <[email protected]> > >> >> > >> >> 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 - [email protected] > >> >> http://lists.ximian.com/mailman/listinfo/mono-winforms-list > >> > > >> > > > > > > _______________________________________________ Mono-winforms-list maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-winforms-list