ObjectListView Control - I want the first column click to be a Descending Sort

38 Views Asked by At

I'm using the ObjectListView object in my C# program, and I want to know if I can change the default Sort behavior.

Out of the box, the control sorts columns in an Ascending order the first time each column is clicked on. But I want the first time each column is sorted to be a Descending sort. Is this possible? The users of my app don't want to have to click every column Twice to get to the Descending sort of the column.

1

There are 1 best solutions below

2
Rev On

This column click sorting behavior is hard coded. Maybe you can work around that, by setting the sort order to "Ascending" on startup (one for each column), so the first click will result in descending.

  /// <summary>
  /// Event handler for the column click event
  /// </summary>
  protected virtual void HandleColumnClick(object sender, ColumnClickEventArgs e) {
      if (!this.PossibleFinishCellEditing())
          return;

      // Toggle the sorting direction on successive clicks on the same column
      if (this.PrimarySortColumn != null && e.Column == this.PrimarySortColumn.Index)
          this.PrimarySortOrder = (this.PrimarySortOrder == SortOrder.Descending ? SortOrder.Ascending : SortOrder.Descending);
      else
          this.PrimarySortOrder = SortOrder.Ascending;

      this.BeginUpdate();
      try {
          this.Sort(e.Column);
      } finally {
          this.EndUpdate();
      }
  }