Chapter 21: Tree and List Controls Visual C++ and MFC Fundamentals
After creating the view, you should initiale it. This is usually done in the
OnInitialUpdate() event of the view class. In order to take advantage of the features of
the list control, you should obtain a reference to the CTreeCtrl class that controls the tree
view. Once you have accessed that reference, you can do anything you would do with a
CTreeCtrl variable or pointer. Here is an example of creating a feww items of a tree
view:
void CExerciseView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
CTreeCtrl& trCtrl = GetTreeCtrl();
HTREEITEM hItem;
hItem = trCtrl.InsertItem( "Cameroon", 0, 2 );
trCtrl.InsertItem( "Yaounde", 1, 3, hItem );
trCtrl.InsertItem( "Douala", 1, 3, hItem );
trCtrl.InsertItem( "Ebolowa", 1, 3, hItem );
hItem = trCtrl.InsertItem( "U.S.A.", 0, 2 );
trCtrl.InsertItem( "Washington, DC", 1, 3, hItem );
trCtrl.InsertItem( "New York", 1, 3, hItem );
hItem = trCtrl.InsertItem( "Germany", 0, 2 );
trCtrl.InsertItem( "Bonn", 1, 3, hItem );
trCtrl.InsertItem( "Francfort", 1, 3, hItem );
}
21.3 The List Control...........................................................................................
21.3.1..Overview...............................................................................................
A list control consists of using one of four views to display a list of items. The list is
typically equipped with icons that indicate what view is displaying. There are four views
used to display items: