void HandleSort(int column) { if (column > -1 && this.AllowSorting && this.Columns[column].AllowSorting) { // get view var view = _view as ICollectionViewEx; var args = new SortingColumnEventArgs(this.Columns[column]); if (this.SortingColumn != null) { SortingColumn(this, args); } if (view != null) { // get column to sort var col = this.Columns[column]; var direction = ListSortDirection.Ascending; var sds = view.SortDescriptions; // get property to sort on var pn = col.BoundPropertyName; if (!string.IsNullOrEmpty(pn)) { if (!args.Cancel) { // apply new sort try { // if already sorted, reverse direction foreach (var sd in sds) { if (sd.PropertyName == pn && sd.Direction == ListSortDirection.Ascending) { direction = ListSortDirection.Descending; break; } } using (view.DeferRefresh()) { sds.Clear(); sds.Add(new SortDescription(pn, direction)); } } catch { } } else { if (this.SortMode == SortMode.Manual) { // if already sorted, reverse direction foreach (var sd in ManualSortDescriptions) { if (sd.PropertyName == pn && sd.Direction == ListSortDirection.Ascending) { direction = ListSortDirection.Descending; break; } } ManualSortDescriptions.Clear(); ManualSortDescriptions.Add(new SortDescription(pn, direction)); this.Invalidate(); } } } else { if (this.SortMode == SortMode.Manual) { var name = this.Columns[column].ColumnName + this.Columns[column].ItemIndex; // if already sorted, reverse direction foreach (var sd in ManualSortDescriptions) { if (sd.PropertyName == name && sd.Direction == ListSortDirection.Ascending) { direction = ListSortDirection.Descending; break; } } ManualSortDescriptions.Clear(); ManualSortDescriptions.Add(new SortDescription(name, direction)); this.Invalidate(); } } } } }
void HandleSort(int column) { if (column > -1 && this.AllowSorting && this.Columns[column].AllowSorting) { // get view var view = _view as ICollectionViewEx; var args = new SortingColumnEventArgs(this.Columns[column]); if (this.SortingColumn != null) { SortingColumn(this, args); } if (view != null) { // get column to sort var col = this.Columns[column]; var direction = ListSortDirection.Ascending; var sds = view.SortDescriptions; // get property to sort on var pn = col.BoundPropertyName; if (!string.IsNullOrEmpty(pn)) { if (!args.Cancel) { // apply new sort try { // if already sorted, reverse direction foreach (var sd in sds) { if (sd.PropertyName == pn && sd.Direction == ListSortDirection.Ascending) { direction = ListSortDirection.Descending; break; } } using (view.DeferRefresh()) { sds.Clear(); sds.Add(new SortDescription(pn, direction)); } } catch { } } else { if (this.SortMode == SortMode.Manual) { // if already sorted, reverse direction foreach (var sd in ManualSortDescriptions) { if (sd.PropertyName == pn && sd.Direction == ListSortDirection.Ascending) { direction = ListSortDirection.Descending; break; } } ManualSortDescriptions.Clear(); ManualSortDescriptions.Add(new SortDescription(pn, direction)); this.Invalidate(); } } } else { if (this.SortMode == SortMode.Manual) { var name = this.Columns[column].ColumnName + this.Columns[column].ItemIndex; // if already sorted, reverse direction foreach (var sd in ManualSortDescriptions) { if (sd.PropertyName == name && sd.Direction == ListSortDirection.Ascending) { direction = ListSortDirection.Descending; break; } } ManualSortDescriptions.Clear(); ManualSortDescriptions.Add(new SortDescription(name, direction)); this.Invalidate(); } } } } }