コード例 #1
0
        protected override void ApplySortCore(PropertyDescriptor property, ListSortDirection direction)
        {
            _sortProperty  = property;
            _sortDirection = direction;

            // Get list to sort
            List <T> items = Items as List <T>;

            // Apply and set the sort, if items to sort
            if (items != null)
            {
                ListSortDescription   sort    = new ListSortDescription(property, direction);
                ListSortDescription[] sortArr = new ListSortDescription[_sortDescriptions.Count + 1];
                _sortDescriptions.CopyTo(sortArr, 1);
                sortArr[0]        = sort;
                _sortDescriptions = new ListSortDescriptionCollection(sortArr);
                ApplySort(_sortDescriptions);
                _isSorted = true;
            }
            else
            {
                _isSorted = false;
            }

            // Let bound controls know they should refresh their views
            OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
        }
コード例 #2
0
ファイル: ExDataView.cs プロジェクト: gybing/dms
 void IBindingListView.ApplySort(ListSortDescriptionCollection sorts)
 {
     ListSortDescription[] sortArray = new ListSortDescription[sorts.Count + 1];
     sorts.CopyTo(sortArray, 1);
     sortArray[0] = fixedSort;
     ApplySort(sortArray);
 }
コード例 #3
0
        private IComparer GetSortComparer(ListSortDescriptionCollection sortDescriptions)
        {
            bool needSubstitution = false;

            if (_sortSubstitutions.Count > 0)
            {
                foreach (ListSortDescription sortDescription in sortDescriptions)
                {
                    if (_sortSubstitutions.ContainsKey(sortDescription.PropertyDescriptor.Name))
                    {
                        needSubstitution = true;
                        break;
                    }
                }

                if (needSubstitution)
                {
                    ListSortDescription[] sorts = new ListSortDescription[sortDescriptions.Count];
                    sortDescriptions.CopyTo(sorts, 0);

                    for (int i = 0; i < sorts.Length; i++)
                    {
                        if (_sortSubstitutions.ContainsKey(sorts[i].PropertyDescriptor.Name))
                        {
                            sorts[i] = new ListSortDescription(((SortSubstitutionPair)_sortSubstitutions[sorts[i].PropertyDescriptor.Name]).Substitute,
                                                               sorts[i].SortDirection);
                        }
                    }

                    sortDescriptions = new ListSortDescriptionCollection(sorts);
                }
            }

            return(new SortListPropertyComparer(sortDescriptions));
        }