Spread 8.0 Documentation
Example
Support Options

Glossary Item Box

Example


The following example sorts the data in the first five columns and rows by two sort keys, based on the first and third columns. The form contains a Spread control and a command button.

C++

void CTestDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
    CDialog::OnShowWindow(bShow, nStatus);

    // Put data in columns and rows 1 through 5
    m_Spread1.SetCol(1);
    m_Spread1.SetCol2(5);
    m_Spread1.SetRow(1);
    m_Spread1.SetRow2(5);
    m_Spread1.SetClip("Tasha\tMix\tUnknown\tGoldie\t7\rKamala\tLab\tSunny\tBrownie\t6\rBJ\tAiredale\tBig Guy\tAiry Terror\t9\rCade\tMix\tUnknown\tMuffy\t4\rTasha\tBorder collie\tCarlton\tDixie\t8");
}

void CTestDlg::OnButton1()
{
    VARIANT vSortKeys, vSortKeyOrders;

    SAFEARRAY * psaSortKeys;
    SAFEARRAY * psaSortKeyOrder;
    SAFEARRAYBOUND rgsabound[1];
    long lIndex = 0;
    long lSortKeys[2] = {1, 3};
    long lSortKeyOrders[2] = {1, 1};

    rgsabound[0].lLbound = 0;
    rgsabound[0].cElements = 2;
    psaSortKeys = SafeArrayCreate(VT_I4, 1, rgsabound);
    psaSortKeyOrder = SafeArrayCreate(VT_I4, 1, rgsabound);

    for( lIndex = 0; lIndex < 2; lIndex++ )
    {
        SafeArrayPutElement(psaSortKeys, &lIndex, &lSortKeys[lIndex]);
        SafeArrayPutElement(psaSortKeyOrder, &lIndex, &lSortKeyOrders[lIndex]);
    }

    vSortKeys.vt = VT_ARRAY | VT_I4;
    vSortKeys.parray = psaSortKeys;
    vSortKeyOrders.vt = VT_ARRAY | VT_I4;
    vSortKeyOrders.parray = psaSortKeyOrder;
    // Sort data in first five columns and rows
    // by column 1 and 3
    m_Spread1.Sort(1, 1, 5, 5, SortByRow, &vSortKeys, &vSortKeyOrders);

    SafeArrayDestroy(psaSortKeys);
    SafeArrayDestroy(psaSortKeyOrder);
}

Visual Basic

Private Sub Command1_Click()
    Dim SortKeys, SortKeyOrder As Variant

    SortKeys = Array(1, 3)
    SortKeyOrder = Array(1, 1)
    ' Sort data in first five columns and rows by column 1 and 3
    fpSpread1.Sort 1, 1, 5, 5, SortByRow, SortKeys, SortKeyOrder
End Sub

Private Sub Form_Load()
    ' Put data in columns and rows 1 through 5
    fpSpread1.Col = 1
    fpSpread1.Col2 = 5
    fpSpread1.Row = 1
    fpSpread1.Row2 = 5
    fpSpread1.Clip = "Tasha" + Chr(9) + "Mix" + Chr(9) + "Unknown" + Chr(9) + "Goldie" + Chr(9) + "7" + Chr(13) + "Kamala" + Chr(9) + "Lab" + Chr(9) + "Sunny" + Chr(9) + "Brownie" + Chr(9) + "6" + Chr(13) + "BJ" + Chr(9) + "Airedale" + Chr(9) + "Big Guy" + Chr(9) + "Airy Terror" + Chr(9) + "9" + Chr(13) + "Cade" + Chr(9) + "Mix" + Chr(9) + "Unknown" + Chr(9) + "Muffy" + Chr(9) + "4" + Chr(13) + "Tasha" + Chr(9) + "Border collie" + Chr(9) + "Carlton" + Chr(9) + "Dixie" + Chr(9) + "8"
End Sub

Copyright © GrapeCity, inc. All rights reserved.