Working with Hierarchical Lists API
Article Metadata
Hierarchical Lists API - as the name suggests, provides an interface for end user applications to present data structures in a hierarchical list format available since S60 Release 5.0 and onwards.
Contents |
CAknSingleStyleTreeList
- Single style hierarchical list.
Header & Library
#include <aknsinglestyletreelist.h>
LIBRARY aknhlist.lib
Capabilities
Capabilities - None
Code can be Self Signed.
Creating CAknSingleStyleTreeList
// where iTreeList is CAknSingleStyleTreeList*
iTreeList = CAknSingleStyleTreeList::NewL();
iTreeList->SetRect(aRect);
Adding Items
void CListExample::ConstructTreeL()
{
_LIT( KParentNode, "Node" );
_LIT( KSubNode, "SubNode" );
_LIT( KLeaf1, "Leaf1" );
_LIT( KLeaf2, "Leaf2" );
// Prepare Node
TUint32 flags1 = CAknSingleStyleTreeList::EPersistent;
TAknTreeItemID mainNode = iTreeList->AddNodeL( KAknTreeIIDRoot, KParentNode,
flags1, EFalse );
// Add leaf to Main Node
TAknTreeItemID leaf1 = iTreeList->AddLeafL( mainNode, KLeaf1, flags1, EFalse );
// Setting it to expanded by default
TUint32 flags2 = CAknSingleStyleTreeList::EExpanded;
// Add another Node under Main Node
TAknTreeItemID subNode = iTreeList->AddNodeL( mainNode, KSubNode,
flags2, EFalse );
// Add Leaf to sub node
TAknTreeItemID leaf2 = iTreeList->AddLeafL( subNode, KLeaf2, flags2, EFalse );
}
Removing Item
// Removing SubNode
iTreeList->RemoveItem( subNode );
Update Item
// Changing title for Main Node //
iTreeList->SetTextL(mainNode, KSomeText, EFalse );
Registering for List Events
/*
* Notifications of common hierarhicial list events are sent to the list client through
* MAknTreeListObserver.
*/
class CListExample : public CCoeControl, public MAknTreeListObserver
{
public:
....
/**
* From MAknTreeListObserver
* Notifications of common hierarhicial list events.
*/
TInt HandleTreeListEvent (CAknTreeList &aList, TAknTreeItemID aItem, TEvent aEvent);
....
}
/**
* Register for receiving list events passing MAknTreeListObserver* (i.e CListExample*
* which * already implements MAknTreeListObserver
*/
iTreeList->AddObserverL( this );
CAknSingleColumnStyleTreeList
- Single style hierarchical column list.
Header & Library
#include <aknsinglecolumnstyletreelist.h>
LIBRARY aknhlist.lib
Capabilities
Capabilities - None
Code can be Self Signed.
Creating CAknSingleColumnStyleTreeList
// where iTreeList is CAknSingleColumnStyleTreeList*
iTreeList = CAknSingleColumnStyleTreeList::NewL();
iTreeList->SetRect(aRect);
Adding Items
void CListExample::ConstructTreeL()
{
_LIT( KParentNode, "Node" );
_LIT( KSubNode, "SubNode" );
_LIT( KLeaf1, "Leaf1" );
_LIT( KLeaf2, "Leaf2" );
// Prepare Node
TUint32 flags1 = CAknSingleColumnStyleTreeList::EPersistent;
TAknTreeItemID mainNode = iTreeList->AddSubtitleRowL( KAknTreeIIDRoot, KParentNode,
flags1, EFalse );
// Add leaf to Main Node
TAknTreeItemID leaf1 = iTreeList->AddSimpleDataRowL( mainNode, KLeaf1, NULL, EFalse );
// Setting it to expanded by default
TUint32 flags2 = CAknSingleColumnStyleTreeList::EExpanded;
// Add another Node under Main Node
TAknTreeItemID subNode = iTreeList->AddSubtitleRowL( mainNode, KSubNode,
flags2, EFalse );
// Add Leaf to sub node
TAknTreeItemID leaf2 = iTreeList->AddSimpleDataRowL( subNode, KLeaf2, NULL, EFalse);
}
Removing Item
// Removing SubNode
iTreeList->RemoveItem( subNode );
Update Item
// Changing title for Main Node //
iTreeList->SetTextL(mainNode, KSomeText, EFalse );
Registering for List Events
/*
* Notifications of common hierarhicial list events are sent to the list client through
* MAknTreeListObserver.
*/
Done in the similar manner as shown above for CAknSingleStyleTreeList.
/**
* Register for receiving list events passing MAknTreeListObserver* (i.e CListExample*
* which * already implements MAknTreeListObserver
*/
iTreeList->AddObserverL( this );
Facts & Constraints
- List cannot be constructed from resources.
- List can be created as both window-owning and non-window-owning.



29 Sep
2009
This article mainly deals with the API for S60 5th Edition for presenting data systematically in Hierarchical Lists. This is a type of Tree list. And author has illustrated to create lists with CAknSingleStyleTreeList and CAknSingleColumnStyleTreeList classes. The code snippests for the same are represented with a well-describing comments and highlighting the necessary libraries and capabilities required. Basic functions like Adding items to the list, Removing items from the list etc. are also covered in the given article. This article also provides image-implementations for our ease.
This article gives primary and brief overview about Hierarchical lists API and it can be very beneficial to beginners.