# Allowing the User to Automatically Sort Rows

Learn how to allow users to automatically sort rows in your spreadsheet with just a click. Find out about the AllowAutoSort property and SetColumnAllowAutoSort method for seamless sorting.

## Content

You can set the spreadsheet to allow the user to automatically sort the data when a column header is clicked. The first time the column header is clicked (selected) the unsorted icon is displayed. The second click displays the sort icon and sorts the column. If the user clicks successively on the same column, then the direction of the sort is reversed. This does not affect the data model, only how the data is displayed. This figure shows the unsorted icon:
![Unsorted Sort Indicator](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/unsortedicon.png)
Use the [Column](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Column.html) object [AllowAutoSort](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Column.AllowAutoSort.html) property or the [SheetView](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.html) [SetColumnAllowAutoSort](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.SetColumnAllowAutoSort.html) method to allow the user to perform automatic sorting when the header cell of a column is clicked. Set the [SortIndicator](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Column.SortIndicator.html) property of the column you want to show the indicator.
The [SetColumShowSortIndicator](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.SetColumnShowSortIndicator.html) method or [ShowSortIndicator](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Column.ShowSortIndicator.html) property can be set to display or hide the sort indicator. The sort indicator appears in the header column as shown in the following figure, illustrating the ascending and descending sort indicators.

| Ascending Sort Indicator | Descending Sort Indicator |
| ------------------------ | ------------------------- |
| ![Ascending Sort Indicator](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/sort-indicator-ascd.png) | ![Descending Sort Indicator](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/sort-indicator-desc.png) |

When a user sorts data, the [AutoSortingColumn](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.FpSpread.AutoSortingColumn.html) event occurs before the sort and then the [AutoSortedColumn](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.FpSpread.AutoSortedColumn.html) event occurs after the sort.

## Using the Properties Window

1. At design time, in the **Properties** window, select the Spread component.
2. Select the **Sheets** property.
3. Click the button to display the **SheetView Collection Editor**.
4. In the **Members** list, select the sheet for which to set up sorting.
5. In the properties list, select the **Columns** property and click the button to open the **Cell, Column, and Row Editor**.
6. Select the columns for which you want to allow automatic sorting.
7. In the properties list, select the **AllowAutoSort** property and set the value to True.
8. Click **OK** to close each of the editors.

## Using a Shortcut

Use either the [AllowAutoSort](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Column.AllowAutoSort.html) property of the columns or the [SetColumnAllowAutoSort](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.SetColumnAllowAutoSort.html) method of the **Sheets** object to allow automatic sorting of the specified columns.
**Example**
This example allows automatic sorting for the first 30 columns in the sheet.

```csharp
fpSpread1.Sheets[0].Columns[0,29].AllowAutoSort = true;
//or
//fpSpread1.Sheets[0].SetColumnAllowAutoSort(0,30,true);
```

```vbnet
fpSpread1.Sheets(0).Columns(0,29).AllowAutoSort = True
'or
'fpSpread1.Sheets(0).SetColumnAllowAutoSort(0,30,True)
```

## Using Code

Use the [AllowAutoSort](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Column.AllowAutoSort.html) property to allow automatic sorting of the specified columns.
**Example**
This example allows automatic sorting for the first 30 columns in the sheet.

```csharp
FarPoint.Win.Spread.Column mycols;
mycols = fpSpread1.ActiveSheet.Columns[0,29];
mycols.AllowAutoSort = true;
```

```vbnet
Dim mycols As FarPoint.Win.Spread.Column
mycols = fpSpread1.ActiveSheet.Columns(0,29)
mycols.AllowAutoSort = True
```

## Using the Spread Designer

1. Select the sheet tab for the sheet for which you want to allow automatic sorting.
2. From the property list for the sheet, select **Columns**. Click on the button to open the **Cell, Column, and Row** editor.
3. Select the columns for which you want to allow automatic sorting.
4. In the properties list, select the **AllowAutoSort** property and set the value to **True**.
5. From the **File** menu choose **Apply and Exit** to apply your changes to the component and exit Spread Designer.

## See Also

[Using Automatic Sorting](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interact-rowcol/spwin-sorting/spwin-sort-setauto)
[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)