首 页 | 新 闻 | Symbian | Android| Windows Mobile | J2ME | 下载中心 | 游戏策划招聘与求职 | 购书指南 | 视频教程
您现在的位置: 开发视界 >> Symbian >> Symbian开发 >> 正文
如何创建listbox
作者:佚名    文章来源:转载    更新时间:2007-11-9 17:10:48

在mmp文件中,加入:

LIBRARY        avkon.lib
LIBRARY        eikcoctl.lib
LIBRARY        eikctl.lib
LIBRARY        bafl.lib

头文件中:

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

在CPP文件中

#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();
    }

相关文章:
如何获取ListBox当前列表项(ListBoxItem)中的文本
如何给ListBox添加滚动效果
Symbian Dynamic ListBox
态生成的对话框上的Listbox加上Scrollbar
在listbox中怎么处理所选项的事件
使用CAknIconArray读取资源图标供listbox所用
SymbianOS Series 60学习笔记二:ListBox控件
ListBox的一点心得!
 

站点地图 | 加入收藏 | 联系站长 | 广告服务 |
QQ:280529124  Tel:0592-8271361 辽ICP备05021703号