DataRange::GetTree

Description

Get the DataRange as a tree.

Syntax

BOOL GetTree( TreeNode & tr, BOOL bOneData = TRUE )

Parameters

tr
[output]a TreeNode to receive the resulting Data Range tree structure
bOneData
[input]TRUE means only one range is added to tree. False means add multiple ranges

Return

TRUE if successful otherwise FALSE.

Examples

EX1

//Create a worksheet with three columns and fill with data.
int  DataRange_GetTree_create_worksheet()
{
    Worksheet wks ;
    wks.Create();
    if( wks )
    {
        while(wks.Columns(0))
            wks.DeleteCol(0);

        wks.AddCol("A");
        wks.AddCol("B");
        wks.AddCol("C");
        double rr;
        for(int j=0; j<3; j++)
        {
            for (int i=0; i<10; i++)
            {
                   rr=rnd();
                   wks.SetCell(i, j, rr*100);
            }
        }
            return 1;
    }
    else 
    {
        return 0;
    }
}

// Create a datarange with three subranges, then get the datarange as a tree.
void DataRange_GetTree_Ex1()
{
    DataRange dr;
    DataRange_GetTree_create_worksheet();
    Worksheet wks = Project.ActiveLayer();
    // A block (A[1]:B[2]).
    dr.Add("Range1", wks, 0, 0, 1, 1);
 
    // A whole row ( row 4) 
    dr.Add("Range2", wks, 3, 0, 3, -1); 
 
    // A whole col (column C)
    dr.Add("Range3", wks, 0, 2, -1, 2);
 
    Tree tr;
    tr.AddNode(IMPTREE_NODE_DATA_RANGE);
    TreeNode trDataRange = tree_check_get_node(tr, IMPTREE_NODE_DATA_RANGE);
    dr.GetTree(trDataRange);//each ranges as a treenode of the tree
    //if false,multiple ranges will be as a treenode of a range belong to the tree
    dr.Destroy();
 
    out_tree(tr);
    DataRange ddr;
    TreeNode tr1 = tr.GetNode(IMPTREE_NODE_DATA_RANGE);
        ddr.Create(tr1);
        if( !ddr )
                return;
    // Modify "Range1"
    ddr.SetRange(0, wks, 0, 0, 3, 2, "Range1");//A block A[1]:C[4].
}

Remark

See Also

DataRange::SetTree

header to Include

origin.h