Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Working with SingleColumnStyleTreeList with Hierarchical Lists API - S60 Touch UI

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleCompatibility
S60 5th Edition
Created: kiran10182 (10 Nov 2008)
Last edited: hamishwillee (08 Feb 2012)



Single Column Style Tree List is created with Hierarchical Lists API to present data in a hierarchical list using text and graphics. In this article we will learn how to create Single Column Style Tree List using Hierarchical List API.

What is Hierarchical Lists API

  • It is used for presenting row data in more manageable hierarchical list using text and grphics.
  • To observe the list items in your application, use the MAknTreeListObserver observer interface.

Single Column Style Tree List

Implementing SingleColumnStyleTreeList component


  • We will inherit our class from MAknTreeListObserver interface and implement its pure virtual method HandleTreeListEvent() to receive and handle events for SingleColumnStyleTreeList.
  • Declare object of CAknSingleColumnStyleTreeList and use it to set observer for this class and handle events on SingleColumnStyleTreeList.
#include <aknSingleColumnStyleTreeList.h>
#include <akntreelist.h>
class CSingleColumnStyleTreeListAppView : public CCoeControl, public MAknTreeListObserver
//From MAknTreeListObserver
virtual void HandleTreeListEvent( CAknTreeList& aList, TAknTreeItemID aItem, TEvent aEvent );
//For SingleColumnStyleTreeList
void CreateHierarchicalSingleColumnStyleListL();
void AddSubTitleL();
void AddCoreDataRowL();
void DeleteSubTitleL();
void DeleteCoreDataRowL();
void DeleteTreeL();
//From CCoeControl
TInt CountComponentControls() const;
CCoeControl* ComponentControl(TInt aIndex) const;
CAknSingleColumnStyleTreeList* iSingleColumnStyleTreeList;


  • Call to create Single Column Style Tree List function from ConstructL() as shown below.
// -----------------------------------------------------------------------------
// CSingleColumnStyleTreeListAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
void CSingleColumnStyleTreeListAppView::ConstructL(const TRect& aRect)
// Create a window for this application view
CreateHierarchicalSingleColumnStyleListL(); //We will create our Single Column Style Tree List in this function
// Set the windows size
// Activate the window, which makes it ready to be drawn
  • Create Single Column Style Tree List and fill the default items.
  • Set "this" as an observer for SingleColumnStyleTreeList and eventually we will receive callbacks in HandleTreeListEvent()
void CSingleColumnStyleTreeListAppView::CreateHierarchicalSingleColumnStyleListL()
iSingleColumnStyleTreeList = CAknSingleColumnStyleTreeList::NewL();
//Setting this class as an observer to receive events for tree list
// Add simple data row to the topmost level of the list.
_LIT( KDataRowText, "Simple Data" );
TAknTreeItemID simpleDataRow = iSingleColumnStyleTreeList->AddSimpleDataRowL( KAknTreeIIDRoot, KDataRowText, KColumnStylePersistent, ETrue );
// Adding first subtitle row for the parent data row
_LIT( KSubtitleRowTextA, "First Subtitle" );
TAknTreeItemID subtitleRowA = iSingleColumnStyleTreeList->AddSubtitleRowL( KAknTreeIIDRoot, KSubtitleRowTextA, NULL, ETrue );
// Add row values for first subtitle row
_LIT( KColumnText1, "Column1a" );
_LIT( KColumnText2, "Column2a" );
TAknTreeItemID coreDataRowA = iSingleColumnStyleTreeList->AddCoreDataRowL(subtitleRowA, KColumnText1, KColumnText2, KColumnStylePersistent, ETrue );
// Adding second subtitle row for the parent data row
_LIT( KSubtitleRowTextB, "Second Subtitle" );
TAknTreeItemID subtitleRowB = iSingleColumnStyleTreeList->AddSubtitleRowL( KAknTreeIIDRoot, KSubtitleRowTextB, NULL, ETrue );
// Add row values for second subtitle row
_LIT( KColumnText3, "Column3b" );
_LIT( KColumnText4, "Column4b" );
TAknTreeItemID coreDataRowB = iSingleColumnStyleTreeList->AddCoreDataRowL( subtitleRowB, KColumnText3, KColumnText4, KColumnStylePersistent, ETrue );
// Adding third subtitle row for the parent data row
_LIT( KSubtitleRowTextC, "Third Subtitle" );
TAknTreeItemID subtitleRowC = iSingleColumnStyleTreeList->AddSubtitleRowL( KAknTreeIIDRoot, KSubtitleRowTextC, NULL, ETrue );
// Add row values for third subtitle row
_LIT( KColumnText5, "Column5c" );
_LIT( KColumnText6, "Column6c" );
TAknTreeItemID coreDataRowC = iSingleColumnStyleTreeList->AddCoreDataRowL( subtitleRowC, KColumnText5, KColumnText6, KColumnStylePersistent, ETrue );
  • We will handle callback events on Single Column Style Tree List control as shown below in the HandleTreeListEvent
void CSingleColumnStyleTreeListAppView::HandleTreeListEvent( CAknTreeList& aList, TAknTreeItemID aItem, TEvent aEvent )
//Process list items on appropriate events
  • Definition for the following functions to return SingleColumnStyleTreeList control.
TInt CSingleColumnStyleTreeListAppView::CountComponentControls() const
return 1; // return number of controls inside this container
CCoeControl* CSingleColumnStyleTreeListAppView::ComponentControl(TInt aIndex) const
switch ( aIndex )
case 0:
return iSingleColumnStyleTreeList;
return NULL;

  • Make sure to delete iSingleColumnStyleTreeList in the destructor of the class.
// -----------------------------------------------------------------------------
// CSingleColumnStyleTreeListAppView::~CSingleColumnStyleTreeListAppView()
// Destructor.
// -----------------------------------------------------------------------------
delete iSingleColumnStyleTreeList;
iSingleColumnStyleTreeList = NULL;

Adding Subtitle to the list

void CSingleColumnStyleTreeListAppView::AddSubTitleL()
// Adding third subtitle row for the parent data row
_LIT( KNewSubtitleRow, "New Subtitle" );
TAknTreeItemID newSubtitleRow = iSingleColumnStyleTreeList->AddSubtitleRowL( KAknTreeIIDRoot, KNewSubtitleRow, NULL, ETrue );

Deleting focused subtitle node from the list

void CSingleColumnStyleTreeListAppView::DeleteSubTitleL()
TAknTreeItemID focusedItem = iSingleColumnStyleTreeList->FocusedItem();

Adding Core Data Row to the focused subtitle node

void CSingleColumnStyleTreeListAppView::AddCoreDataRowL()
TAknTreeItemID focusedItem = iSingleColumnStyleTreeList->FocusedItem();
// Add row values for third subtitle row
_LIT( KNewColumnText1, "NewColumn1" );
_LIT( KNewColumnText2, "NewColumn2" );
TAknTreeItemID newCoreDataRow = iSingleColumnStyleTreeList->AddCoreDataRowL( focusedItem, KNewColumnText1, KNewColumnText2, KColumnStylePersistent, ETrue );

Deleting core data row from the focused subtitle node

void CSingleColumnStyleTreeListAppView::DeleteCoreDataRowL()
TAknTreeItemID focusedItem = iSingleColumnStyleTreeList->FocusedItem();

Deleting whole tree

void CSingleColumnStyleTreeListAppView::DeleteTreeL()
if(! iSingleColumnStyleTreeList->IsEmpty(KAknTreeIIDRoot))

Useful functions


  • AddSubtitleRowL()
  • AddCoreDataRowL()
  • EnableThirdColumn()
  • IsThirdColumnEnabled()
  • SetTextL()
  • SetIcon()


  • RemoveItem()
  • ExpandNode()
  • CollapseNode()
  • FocusedItem()
  • AddIconL()


  • HandleTreeListEvent()



  • #include <aknSingleColumnStyleTreeList.h>
  • #include <akntreelist.h>


  • CAknSingleColumnStyleTreeList
  • CAknTreeList
  • MAknTreeListObserver


  • aknhlist.lib

Example Application

Related links

Reference list

This page was last modified on 8 February 2012, at 04:59.
27 page views in the last 30 days.