Namespaces

Variants
Actions

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 over the next few weeks. Thanks for all your past and future contributions.

Revision as of 04:33, 30 May 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to create a simple listbox in Symbian C++

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: vin2ktalks (29 Mar 2007)
Last edited: hamishwillee (30 May 2013)

Here is the code snippet to create a simple listbox:

In mmp file:

LIBRARY        avkon.lib 
LIBRARY eikcoctl.lib
LIBRARY eikctl.lib
LIBRARY bafl.lib

In the header file:

// FORWARD DECLARATION
class CEikColumnListBox;
// ...
 
class CMyAppContainer : public CCoeControl
{
// ...
 
public: // New functions
 
/**
* Create the listbox.
*/

void CreateListBoxL();
 
/**
* Initialize the listbox.
*/

void InitListBoxL();
 
private: // Data members
 
/**
* The listbox object
* Owned by CMyAppContainer.
*/

CEikColumnListBox* iListBox;
};

In the cpp file:

#include <eikclb.h>   // for CEikColumnListBox 
#include <aknlists.h> // for CAknSingleStyleListBox
#define KGranularityOfArray 10;
// ----------------------------------------------------------------------------
// CMyAppContainer::CreateListBoxL()
// Create the listbox.
// ----------------------------------------------------------------------------
//
void CMyAppContainer::CreateListBoxL()
{
//Delete the list box if already exists.
if ( iListBox )
{
delete iListBox;
iListBox = NULL;
}
 
// listbox instance
iListBox = new (ELeave) CAknSingleStyleListBox();
iListBox->ConstructL(this);
iListBox->SetContainerWindowL(*this);
 
// add scrollbars to listbox
iListBox->CreateScrollBarFrameL(ETrue);
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto );
 
const TPoint aPoint(0,0);
const TSize aSize(180,150);
 
//most important line , else the list box simply disappears
iListBox->SetExtent(aPoint,aSize);
 
//Fill list box with the data
InitListBoxL();
 
iListBox->ActivateL();
iListBox->DrawNow();
}
 
 
// ----------------------------------------------------------------------------
// CMyAppContainer::InitListBoxL()
// Initialize the listbox.
// ----------------------------------------------------------------------------
//
void CMyAppContainer::InitListBoxL()
{
// construct listbox item array
CDesCArray *itemList = new (ELeave) CDesCArrayFlat(KGranularityOfArray);
 
itemList->AppendL(_L("\tFirst item\t\t"));
itemList->AppendL(_L("\tSecond item\t\t"));
 
// set items and ownership
iListBox->Model()->SetItemTextArray(itemList);
iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
 
iListBox->SetCurrentItemIndex(0);
iListBox->SetFocus(ETrue);
iListBox->HandleItemAdditionL();
}


Other Related Links


This page was last modified on 30 May 2013, at 04:33.
71 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×