# Using Automatic Sorting

Implement automatic sorting of columns using the SetColumnAllowAutoSort and SetColumnShowSortIndicator methods. See code examples for sorting the first column in C# and VB.

## Content

You can sort entire rows or columns automatically in a sheet. The component automatically sorts the rows in a sheet according to the specified column in ascending order unless the sheet was previously automatically sorted ascending. The automatic sorting displays the sort indicator unless the sort indicator for the column has been disabled. This does not affect the data model, only how the data is displayed. Different overloads provide different ways to perform the sorting.
Use the [AutoSortColumn](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.AutoSortColumn.html) method to sort the display in a sheet automatically according to the specified key and use the [SetColumShowSortIndicator](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.SetColumnShowSortIndicator.html) to set whether to display the sort indicator. The [AutoSortColumn](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.AutoSortColumn.html) method performs the same action as clicking in the column header of the specified column that has its [AllowAutoSort](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Column.AllowAutoSort.html) property set to True. The [AllowAutoSort](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Column.AllowAutoSort.html) property does not need to be set to True to use this method. If this method is called successively with the same column index, then the direction of the sort is reversed. If the method is called with a different column index, then the previously sorted column's sort indicator is changed back to **SortIndicator.None** (if there is one) and the specified column is used as the key column in a call to [SortRows](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.SortRows.html) to sort all the rows in the sheet by that column. This affects only the arrangement of rows or columns on a sheet and does not change the arrangement of the data; that is, this does not affect the data model, only how the data is displayed.

> !type=note
> **Note:** The [SetColumShowSortIndicator](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.SetColumnShowSortIndicator.html) method must be called before the [AutoSortColumn](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.AutoSortColumn.html) method; otherwise, the sort indicator is shown and remains displayed.

## Using Code

1. Allow the automatic sorting of a column or columns by using the [SetColumnAllowAutoSort](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.SetColumnAllowAutoSort.html) method.
2. If you want to display a sort indicator, set the column to show the sort indicator with the [SetColumnShowSortIndicator](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.SetColumnShowSortIndicator.html) method.
3. Perform the automatic sort by setting the [AutoSortColumn](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.AutoSortColumn.html) method.

## Example

This example automatically sorts the first column.

```csharp
fpSpread1.ActiveSheet.SetColumnAllowAutoSort(0, true);
fpSpread1.ActiveSheet.SetColumnShowSortIndicator(0, false);
fpSpread1.ActiveSheet.AutoSortColumn(0);
```

```vbnet
fpSpread1.ActiveSheet.SetColumnAllowAutoSort(0, True)
FpSpread1.ActiveSheet.SetColumnShowSortIndicator(0, False)
FpSpread1.ActiveSheet.AutoSortColumn(0)
```

## See Also

[Allowing the User to Automatically Sort Rows](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interact-rowcol/spwin-sorting/spwin-sort-setuser)
[Sorting Rows, Columns, or Ranges](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interact-rowcol/spwin-sorting/spwin-sort-rowcolrange)
[Setting the Appearance of Sort Indicators](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interact-rowcol/spwin-sorting/spwin-sort-indicators)
[Managing Cell Range Sorting](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interact-rowcol/spwin-sorting/spwin-sort-range)