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.

Archived:Adding items to listbox dynamically

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Platform(s): S60 3rd Edition FP 1
S60 3rd Edition FP1
Keywords: CAknDoubleLargeStyleListBox
Created: vdharankar (27 Apr 2009)
Last edited: hamishwillee (15 Jun 2012)

How to add an item to a CAknDoubleLargeStyleListBox

This article describes the process of adding an item to an Avkon listbox at runtime.

Two steps are necessary:

  1. Create text item and add it to the text item array
  2. Create the icon and add it to the icons array

Both the items should be assigned to the same index remember else you may landup with panic AVKON 0

  1. Create text item and add it to the text item array
    TBuf16<100> b;
    CTextListBoxModel* model =iListBox->Model();
    CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() );
  2. Create Icon and add it to the icons array - this is bit tricky
    CGulIcon* YourClass::GetIconFromResource()
    CGulIcon* icon;
    icon = LoadAndScaleIconL(
    KYourResourceFile, EMbmIconId, -1,
    NULL, EAspectRatioPreserved );
    return icon;
    CGulIcon* YourClass::LoadAndScaleIconL(
    const TDesC& aFileName,
    TInt aBitmapId,
    TInt aMaskId,
    TSize* aSize,
    TScaleMode aScaleMode )
    CFbsBitmap* bitmap;
    CFbsBitmap* mask;
    AknIconUtils::CreateIconL( bitmap, mask, aFileName, aBitmapId, aMaskId );
    TSize size;
    if ( aSize == NULL )
    // Use size from the image header. In case of SVG,
    // we preserve the image data for a while longer, since ordinarily
    // it is disposed at the first GetContentDimensions() or SetSize() call.
    AknIconUtils::PreserveIconData( bitmap );
    AknIconUtils::GetContentDimensions( bitmap, size );
    size = *aSize;
    AknIconUtils::SetSize( bitmap, size, aScaleMode );
    AknIconUtils::SetSize( mask, size, aScaleMode );
    if ( aSize == NULL )
    AknIconUtils::DestroyIconData( bitmap );
    return CGulIcon::NewL( bitmap, mask );
  3. Add the created icon to the list box.
    CArrayPtr<CGulIcon>* iconList=iListBox->ItemDrawer()->ColumnData()->IconArray();
  4. Finally, you need to notify the listbox that new items have been added

Placing this code in appropriate class is your responsibility :) You may need to slightly change this code based on the location of your listbox

Related Links:

This page was last modified on 15 June 2012, at 06:33.
53 page views in the last 30 days.