Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / Tables / Sorting a Table
In This Topic
    Sorting a Table
    In This Topic

    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

    Using Code

    Use the Sort method to sort columns in a table.

    Example

    This example code sorts the column.

    C#
    Copy Code
    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);
    
    VB
    Copy Code
    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