# Sorting a Table

Discover the efficient method to sort columns in a table using Spread.NET's Sort method. Access an example code for sorting a specific column effortlessly.

## Content

You can sort a table by selecting the drop-down icon and selecting a sort option, as shown in the following figure, or by using code.
![Table Sort](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/tablesort.png)

## Using Code

Use the [Sort](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.TableView.Sort.html) method to sort columns in a table.

## Example

This example code sorts the column.

```csharp
FarPoint.Win.Spread.TableStyle tstyle = fpSpread1.CreateTableStyle("Style1", FarPoint.Win.Spread.TableStyle.TableStyleLight2);
fpSpread1.Sheets[0].Cells[1, 1].Text = "Last Name";
fpSpread1.Sheets[0].Cells[1, 2].Text = "Value";
fpSpread1.Sheets[0].Cells[2, 1].Text = "Smith";
fpSpread1.Sheets[0].Cells[2, 2].Value = 50;
fpSpread1.Sheets[0].Cells[3, 1].Text = "Vil";
fpSpread1.Sheets[0].Cells[3, 2].Value = 10;
fpSpread1.Sheets[0].Cells[4, 1].Text = "Press";
fpSpread1.Sheets[0].Cells[4, 2].Value = 78;
fpSpread1.TableStyleCollection.Add(tstyle);
FarPoint.Win.Spread.TableView table = fpSpread1.Sheets[0].AddTable("table", 1, 1, 5, 2, "Style1");
FarPoint.Win.Spread.ComplexSortInfo[] sort = new FarPoint.Win.Spread.ComplexSortInfo[1];
sort[0] = new FarPoint.Win.Spread.ComplexSortInfo(1, true);
table.Sort(sort);
```

```vbnet
Dim tstyle As FarPoint.Win.Spread.TableStyle
tstyle = fpSpread1.CreateTableStyle("Style1", FarPoint.Win.Spread.TableStyle.TableStyleLight2)
fpSpread1.Sheets(0).Cells(1, 1).Text = "Last Name"
fpSpread1.Sheets(0).Cells(1, 2).Text = "Value"
fpSpread1.Sheets(0).Cells(2, 1).Text = "Smith"
fpSpread1.Sheets(0).Cells(2, 2).Value = 50
fpSpread1.Sheets(0).Cells(3, 1).Text = "Vil"
fpSpread1.Sheets(0).Cells(3, 2).Value = 10
fpSpread1.Sheets(0).Cells(4, 1).Text = "Press"
fpSpread1.Sheets(0).Cells(4, 2).Value = 78
fpSpread1.TableStyleCollection.Add(tstyle)
Dim table As FarPoint.Win.Spread.TableView = fpSpread1.Sheets(0).AddTable("table", 1, 1, 5, 2, "Style1")
Dim sort As FarPoint.Win.Spread.ComplexSortInfo() = New FarPoint.Win.Spread.ComplexSortInfo(0) {}
sort(0) = New FarPoint.Win.Spread.ComplexSortInfo(1, True)
table.Sort(sort)
```

## See Also

[Tables](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-tables)
[Adding a Table](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-tables/spwin-tableadd)
[Using Table Filters](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-tables/spwin-tablefilter)
[Resizing a Table](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-tables/spwin-tableresize)
[Setting Table Styles](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-tables/spwin-tablestyle)
[Adding a Table Formula](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-tables/tableformula)
[Understanding Structured References](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-tables/spwin-structref)