×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    254

    how to display the Listbox

    I have taken an example from the Manual Page and i want to run it to display the listBox...
    I am unable to figure out how to do it. I have tried but it is not successful..




    Creating a selection listbox runtime
    Creating lists without resource file definitions is fairly simple. In this approach, the listbox format and contents are set manually at run time as the resources are not used. To create a listbox at run time, follow these steps:

    Create a new listbox instance. Depending on which type of listbox you wish to create, you must select and instantiate an appropriate class. This example uses the CAknSingleNumberStyleListBox class.
    Use flag EAknListBoxSelectionList to create a selection list.
    Set the listbox’s container window. Since the listbox is a non window-owning control, its parent control is passed as a parameter, providing a window for the listbox to draw to.
    Create a scrollbar frame to the listbox and set active.
    Construct the list item array. The listbox item string format must obey the string format specified for the listbox type used. Append the formatted item strings to the listbox item array.
    Set the listbox item array to list and set the item array ownership to list.

    The following example code shows how to create a numbered selection listbox with three items at run time, without using a resource file. Note that the example listbox is a component of a compound control and it is needed to implement method ComponentControl() and CountComponentControls().

    class CMyContainer : public CCoeControl
    {
    CEikTextListBox* iListBox;
    CDesCArrayFlat* iListBoxItems;
    }

    void CMyContainer::ConstructL()
    {

    CreateWindowL(); // This is a window owning control
    // Create a single numbered style listbox
    iListBox = new (ELeave) CAknSingleNumberStyleListBox(); // markable
    // Construct listbox
    iListBox->ConstructL( this, EAknListBoxSelectionList | EAknListBoxLoopScrolling );
    iListBox->SetContainerWindowL( *this );
    // Set scrollbars
    iListBox->CreateScrollBarFrameL( ETrue );
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto );

    // Create listbox item array
    iListBoxItems = new (ELeave) CDesCArrayFlat(4);
    // Create listbox items
    iListBoxItems->AppendL( _L("1\tItem") );
    iListBoxItems->AppendL( _L("2\tItem") );
    iListBoxItems->AppendL( _L("3\tItem") );
    // Add items to listbox
    iListBox->Model()->SetItemTextArray( iListBoxItems );
    // Listbox deletes the item array
    iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
    iListBox->HandleItemAdditionL( );
    // Activate Listbox
    iListBox->SetRect( Rect() );
    iListBox->ActivateL();

    }

    Note, that listbox must be informed about size changed events, to display properly.

    void CSumoTestContainer::SizeChanged()
    {

    iListBox->SetRect( Rect() );

    }
    regards
    Arun gupta

  2. #2
    Regular Contributor
    Join Date
    May 2003
    Location
    India
    Posts
    136

    Re: how to display the Listbox

    try this
    void YourClass :: ShowListL( CDesCArray* anArray )
    {
    // create CEikTextListBox instance, list
    CEikTextListBox* list = new( ELeave ) CAknSinglePopupMenuStyleListBox;

    // push list'pointer to CleanupStack.
    CleanupStack::PushL( list );

    // create CAknPopupList instance, popupList
    CAknPopupList* popupList = CAknPopupList::NewL( list,
    R_AVKON_SOFTKEYS_OK_EMPTY,
    AknPopupLayouts::EMenuWindow );
    // push popupList'pointer to CleanupStack.
    CleanupStack::PushL( popupList );

    // initialize listbox.
    list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect );
    list->CreateScrollBarFrameL( ETrue );
    list->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
    CEikScrollBarFrame::EAuto );

    // set listitems.
    CTextListBoxModel* model = list->Model();
    model->SetItemTextArray( anArray );
    model->SetOwnershipType( ELbmDoesNotOwnItemArray );

    // show popup list and then show return value.
    popupList->ExecuteLD();

    // pop the popupList's pointer from CleanupStack
    CleanupStack::Pop();

    // pop and Destroy the list's pointer from CleanupStack
    CleanupStack::PopAndDestroy();
    }

  3. #3
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    254

    Re: how to display the Listbox

    hi deepak

    Thanks a lot for the code snippet..

    deepak my need is to create the listbox without using the resource file

    i got the necessary idea from your code and i will try for its implementation

    regards
    Arun Gupta '

  4. #4
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,143

    Re: how to display the Listbox

    Ok, What is not working with your code ?

    i.e. what is observed to happen, and what would you want to happen ?, is there any error's shown, have you debugged and seen that all is executed nicely..

    anyway, did you remember to implement the ComponentControl & CountComponentControls functions on your container, as well as forard the key events in the offerkey function ?

  5. #5
    Nokia Developer Moderator
    Join Date
    Jan 2008
    Location
    Moscow, Russia
    Posts
    3,347

    Re: how to display the Listbox

    Quote Originally Posted by arungupta_2jan
    my need is to create the listbox without using the resource file
    These links may be helpful for you:
    - How to create a simple listbox
    - List box example

Similar Threads

  1. Nokia N-Series Complete Model Line-Up
    By Dopod in forum General Development Questions
    Replies: 6
    Last Post: 2008-07-22, 20:16
  2. Display problem in second listbox???
    By chandantheracer in forum Symbian
    Replies: 1
    Last Post: 2007-04-18, 12:19
  3. Replies: 2
    Last Post: 2006-11-29, 08:35
  4. Listbox Display
    By shilpav in forum Symbian User Interface
    Replies: 2
    Last Post: 2004-11-08, 07:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •