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

Reply With Quote

