You Are Here:

Community: Wiki

This page was last modified on 9 September 2009, at 05:00.

How to create a simple listbox

From Forum Nokia Wiki

Reviewer Approved   

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
 
// ----------------------------------------------------------------------------
// 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


Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fE25E455E25A6E2582E25E454E25BE44E2595E25E455E259CE25A8E25E456E2594E25B6E25E454E25BBE25B6E25E457E25AE45E25B1E25E455E2588E259BE25E455E25BBE25BAE25E457E259FE25AE44E25E454E25BFE25A1X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxs60X qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx5E2E0000X