dt=New Table( "Food Tree",
Add Rows( 8 ),
New Column( "Name",
Character,
"Nominal",
Set Selected,
Set Values(
{"Apple", "Banana", "Watermelon", "Fruit", "Broccoli", "Lettuce",
"Potato", "Vegetable"}
)
),
New Column( "Category",
Character,
"Nominal",
Set Values(
{"Fruit", "Fruit", "Fruit", "", "Vegetable", "Vegetable", "Vegetable",
""}
)
),
New Column( "Level",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2, 2, 2, 1, 2, 2, 2, 1] )
),
Set Row States( [0, 0, 0, 1, 0, 0, 0, 0] )
);
relations = [=>];
For Each Row( dt,
relations[:Name] = Tree Node( :Name );
relations[:Name] <<Set Data( Eval List( {:Name, :Category, :Level} ) );
);
roots = {};
For Each Row( dt,
If( :Category != "" & relations << Contains( :Category ),
relations[:Category] << Append( relations[:Name] )
,
roots[N Items( roots ) + 1] = relations[:Name]
);
);
New Window( "TreeBox Tests",
tree = Tree Box( roots, Size( 300, 500 ) ) );
key = relations << First;
While( !Is Empty( key ),
Try( tree << Expand( relations[key] ) );
key = relations << Next( key )
);
tree << Set Node Select Script(
Function( {this, node},
Print( node << Get Data )
)
);