public void Sort(bool stable)
{
// don't allow sorting if we're being used as a
// preview table in a ColumnModel editor
if (this.Preview)
{
return;
}
// if we don't have a sorted column already, check if
// we can use the column of the cell that has focus
if (!this.IsValidColumn(this.lastSortedColumn))
{
if (this.IsValidColumn(this.focusedCell.Column))
{
this.lastSortedColumn = this.focusedCell.Column;
}
}
// make sure the last sorted column exists
if (this.IsValidColumn(this.lastSortedColumn))
{
// don't bother if the column won't let us sort
if (!this.ColumnModel.Columns[this.lastSortedColumn].Sortable)
{
return;
}
// work out which direction we should sort
SortOrder newOrder = SortOrder.Ascending;
Column column = this.ColumnModel.Columns[this.lastSortedColumn];
if (column.SortOrder == SortOrder.Ascending)
{
newOrder = SortOrder.Descending;
}
this.Sort(this.lastSortedColumn, column, newOrder, stable);
}
}