BExplorer.Shell.ShellView.SetSortCollumn C# (CSharp) Method

SetSortCollumn() public method

public SetSortCollumn ( Boolean isReorder, Collumns column, SortOrder order, Boolean reverseOrder = true ) : void
isReorder Boolean
column Collumns
order SortOrder
reverseOrder Boolean
return void
    public void SetSortCollumn(Boolean isReorder, Collumns column, SortOrder order, Boolean reverseOrder = true) {
      if (column == null) return;
      try {
        var itemsArray = this.Items;
        var selectedItems = this.SelectedItems.ToArray();
        if (column.ID == this.LastSortedColumnId && reverseOrder) {
          // Reverse the current sort direction for this column.
          this.LastSortOrder = this.LastSortOrder == SortOrder.Ascending ? SortOrder.Descending : SortOrder.Ascending;
        } else {
          // Set the column number that is to be sorted; default to ascending.
          this.LastSortedColumnId = column.ID;
          this.LastSortOrder = order;
        }
        if (isReorder) {
          var itemsQuery = itemsArray.Where(w => this.ShowHidden || !w.IsHidden).OrderByDescending(o => o.IsFolder);
          if (column.CollumnType != typeof(String)) {
            if (order == SortOrder.Ascending) {
              this.Items =
                              itemsQuery.ThenBy(
                                              o =>
                                                              o.GetPropertyValue(column.pkey, typeof(String)).Value ?? "1")
                                              .ToList();
            } else {
              this.Items =
                              itemsQuery.ThenByDescending(
                                              o =>
                                                              o.GetPropertyValue(column.pkey, typeof(String)).Value ?? "1")
                                              .ToList();
            }
          } else {
            if (order == SortOrder.Ascending) {
              this.Items =
                              itemsQuery.ThenBy(
                                              o =>
                                                              o.GetPropertyValue(column.pkey, typeof(String)).Value == null
                                                                              ? "1"
                                                                              : o.GetPropertyValue(column.pkey, typeof(String)).Value.ToString(), NaturalStringComparer.Default)
                                              .ToList();
            } else {
              this.Items =
                              itemsQuery.ThenByDescending(
                                              o =>
                                                              o.GetPropertyValue(column.pkey, typeof(String)).Value == null
                                                                              ? "1"
                                                                              : o.GetPropertyValue(column.pkey, typeof(String)).Value.ToString(), NaturalStringComparer.Default)
                                              .ToList();
            }
          }
          var i = 0;
          this.Items.ForEach(e => e.ItemIndex = i++);
        }
        this.BeginInvoke((Action)(() => {
          this._IIListView.SetItemCount(this.Items.Count, 0x2);
        }));

        var colIndexReal = this.Collumns.IndexOf(this.Collumns.FirstOrDefault(w => w.ID == this.LastSortedColumnId));
        if (colIndexReal > -1) {
          User32.SendMessage(this.LVHandle, MSG.LVM_SETSELECTEDCOLUMN, colIndexReal, 0);
          this.SetSortIcon(colIndexReal, order);
        } else {
          User32.SendMessage(this.LVHandle, MSG.LVM_SETSELECTEDCOLUMN, -1, 0);
        }

        if (!this.IsRenameInProgress) this.SelectItems(selectedItems);
      } catch {
      }
    }
ShellView