示例#1
0
        private List <TreeNode> SortNodes(SortColumnDescriptions sortColumnDescriptions, SortComparers sortComparers)
        {
            var list = nodeList;
            IOrderedEnumerable <TreeNode> source = null;

            for (int i = 0; i < sortColumnDescriptions.Count; i++)
            {
                var sortDescription = sortColumnDescriptions[i];
                var customComparer  = sortComparers[sortDescription.ColumnName];
                if (sortDescription.SortDirection == ListSortDirection.Ascending)
                {
                    if (i == 0)
                    {
                        if (customComparer == null)
                        {
                            source = list.OrderBy(node => TreeGridHelper.GetValue(node.Item, sortDescription.ColumnName));
                        }
                        else
                        {
                            source = list.OrderBy(node => node.Item, customComparer);
                        }
                    }
                    else
                    {
                        if (customComparer == null)
                        {
                            source = source.ThenBy(node => TreeGridHelper.GetValue(node.Item, sortDescription.ColumnName));
                        }
                        else
                        {
                            source = source.ThenBy(node => node.Item, customComparer);
                        }
                    }
                }
                else
                {
                    if (i == 0)
                    {
                        if (customComparer == null)
                        {
                            source = list.OrderByDescending(node => TreeGridHelper.GetValue(node.Item, sortDescription.ColumnName));
                        }
                        else
                        {
                            source = list.OrderByDescending(node => node.Item, customComparer);
                        }
                    }
                    else
                    {
                        if (customComparer == null)
                        {
                            source = source.ThenByDescending(node => TreeGridHelper.GetValue(node.Item, sortDescription.ColumnName));
                        }
                        else
                        {
                            source = source.ThenByDescending(node => node.Item, customComparer);
                        }
                    }
                }
            }
            return(source.ToList());
        }
示例#2
0
 internal void Sort(SortColumnDescriptions descriptions, SortComparers comparers)
 {
     nodeList = SortNodes(descriptions, comparers);
 }