Spread 8.0 Documentation
Example
Support Options

Glossary Item Box

Example


The following example lets users sort the data in the sheet by last name or by ZIP code. The example uses the SortKey and SortKeyOrder properties instead of the SortKeys and SortKeyOrders parameters in the Sort method.

To access the file used in this sample, change the path in the code to the path for your product installation's \SAMPLES\FILES directory.

C++

void CTestDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
    BOOL ret;
    // Label commmand buttons
    m_Command1.SetWindowText("Sort By Last Name");
    m_Command2.SetWindowText("Sort By ZIP Code ");
    // Load data in sheet
    ret = m_Spread1.LoadFromFile("C:\\Samples\\Files\\address.ss7");
}

void CTestDlg::OnButton1()
{
    // Sort by last name in ascending order
    m_Spread1.SetSortKey(1,2);
    m_Spread1.SetSortKeyOrder(1, SortKeyOrderAscending);
    m_Spread1.Sort(-1, -1, -1, -1, SortByRow, NULL, NULL);
}

void CTestDlg::OnButton2()
{
    // Sort by ZIP Code in descending order
    m_Spread1.SetSortKey(1,7);
    m_Spread1.SetSortKeyOrder(1, SortKeyOrderDescending);
    m_Spread1.Sort(-1, -1, -1, -1, SortByRow, NULL, NULL);
}

Visual Basic

Private Sub Form_Load()
    ' Label commmand buttons
    Command1.Caption = "Sort By Last Name"
    Command2.Caption = "Sort By ZIP Code"
    ' Load data in sheet
    fpSpread1.LoadFromFile "C:\Samples\Files\address.ss7"
End Sub

Private Sub Command1_Click()
    ' Sort by last name in ascending order
    fpSpread1.SortKey(1) = 2
    fpSpread1.SortKeyOrder(1) = SortKeyOrderAscending
    fpSpread1.Sort -1, -1, -1, -1, SortByRow
End Sub

Private Sub Command2_Click()
    ' Sort by ZIP Code in descending order
    fpSpread1.SortKey(1) = 7
    fpSpread1.SortKeyOrder(1) = SortKeyOrderDescending
    fpSpread1.Sort -1, -1, -1, -1, SortByRow
End Sub

© 2002-2014 ComponentOne, a division of GrapeCity. All Rights Reserved.