List Box Construction
Here is how we construct a list box
TInt flags( CEikListBox::EPopout | CEikListBox::ELeftDownInViewRect );
iListBox = new( ELeave ) CEikColumnListBox;
iListBox->ConstructL( this, flags );
iListBox->SetListBoxObserver( iHandler );
iListBox->SetBorder( TGulBorder::EShallowRaised );
iListBox->CreateScrollBarFrameL( ETrue );
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
// Creates list items
CDesCArray* textArray = iCoeEnv->ReadDesCArrayResourceL( resourceId );
iListBox->Model()->SetItemTextArray( textArray );
iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
// Sets pixel values of width.
TRect rect(TPoint(KAknExQueryListBoxRectPointX,
KAknExQueryListBoxRectPointY),
TSize(KAknExQueryListBoxRectWidth,
KAknExQueryListBoxRectHeight) );
CColumnListBoxData* columnData = iListBox->ItemDrawer()->ColumnData();
columnData->SetColumnWidthPixelL( KAknExQueryNameColumnIndex,
rect.Width() );
columnData->SetColumnWidthPixelL( KAknExQueryNameGapColumnIndex,
rect.Width() );
// Gets current number of list box items.
TInt numberOfItems( iListBox->Model()->NumberOfItems() );
// Gets new height of list box.
TInt height( iListBox->CalcHeightBasedOnNumOfItems( numberOfItems ) );
// If new height is less than defined height of list box
// sets new height to list box height.
if ( height < rect.Height() )
{
rect.SetHeight( height );
}
iListBox->SetRect( rect ); // Sets rectangle of list box.
ActivateL();
TInt flags( CEikListBox::EPopout | CEikListBox::ELeftDownInViewRect );
iListBox = new( ELeave ) CEikColumnListBox;
iListBox->ConstructL( this, flags );
iListBox->SetListBoxObserver( iHandler );
iListBox->SetBorder( TGulBorder::EShallowRaised );
iListBox->CreateScrollBarFrameL( ETrue );
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
// Creates list items
CDesCArray* textArray = iCoeEnv->ReadDesCArrayResourceL( resourceId );
iListBox->Model()->SetItemTextArray( textArray );
iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
// Sets pixel values of width.
TRect rect(TPoint(KAknExQueryListBoxRectPointX,
KAknExQueryListBoxRectPointY),
TSize(KAknExQueryListBoxRectWidth,
KAknExQueryListBoxRectHeight) );
CColumnListBoxData* columnData = iListBox->ItemDrawer()->ColumnData();
columnData->SetColumnWidthPixelL( KAknExQueryNameColumnIndex,
rect.Width() );
columnData->SetColumnWidthPixelL( KAknExQueryNameGapColumnIndex,
rect.Width() );
// Gets current number of list box items.
TInt numberOfItems( iListBox->Model()->NumberOfItems() );
// Gets new height of list box.
TInt height( iListBox->CalcHeightBasedOnNumOfItems( numberOfItems ) );
// If new height is less than defined height of list box
// sets new height to list box height.
if ( height < rect.Height() )
{
rect.SetHeight( height );
}
iListBox->SetRect( rect ); // Sets rectangle of list box.
ActivateL();
0 Comments:
Post a Comment
<< Home