ListBox: Part VII

7. Creating a ListBox from a resource file
Keywords:

ListBox resource is described using LISTBOX structure (defined in uikon.rh).

STRUCT LISTBOX
{
 BYTE version; // version number
 WORD flags;
 WORD height;  // in items
 WORD width;   // in chars
 LLINK array_id;   // points to items in ARRAY structure
}

ListBox content (items) are also represented by a resource. Items are described using ARRAY structure (also in uikon.rh). Each individual item is defined using LBUF resource structure.

STRUCT ARRAY
{
   STRUCT items[];
}

In an application resource file (.rss), a listbox definition will look something like this:

RESOURCE LISTBOX r_my_listbox
{
   flags = EAknListBoxSelectionList;
   array_id = r_mylistbox_items;
}

RESOURCE ARRAY r_mylistbox_items
{
   items =
   {
       LBUF { txt = "Item1"; },
       LBUF { txt = "Item2"; },
       LBUF { txt = "Item3"; }
   };
}

(An application can have any number of LISTBOX and ARRAY structures.)

The C++ code that reads above LISTBOX resource could look something like this:

ListBox Container code:

// Create CEikColumnListBox-derived or CEikFormattedCellListBox-derived object
CEikColumnListBox* listBox = new (ELeave) ...;

TInt resourceId = R_MY_LISTBOX;
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC(reader, resourceId);
listBox->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // resource pushed in CreateResourceReaderLC

// create listbox scrollbar...
// set icons...

SizeChanged();
listBox->ActivateL();
DrawNow();


:<: Part VI
Part VIII :>:


why can't I use CEikColumnListBox ?

I added a member variable named iListBox with the type CEikColumnListBox to a container class in my project and built it in vc6 , while an error occured at link time which said : unresolved external symbol "public: __thiscall CEikColumnListBox::CEikColumnListBox(void)". But why ? Should I add any other class or header file or library file to my project so as to solve this problem ? Thanks.

> why can't I use CEikColumnListBox ?

generally when u do not add library for that particular control in .mmp file then linking error occurs, add eikctl.lib and include eikclb.h as a header file and try, i think then it will work.

All the best

Amit

> ListBox: Part VII

i have added this code in .rss and ...container.cpp but it gives 'R_MY_LISTBOX' : undeclared identifier

how can i solve?

> ListBox: Part VII

You also need to include your *.rsg file

ListBox: Part VII

What's this .rsg file?

When I try to compile my code I always get this error "the file *.rsg cannot be opened"

Re: ListBox: Part VII

How can I change the view from List view to Grid View and Vice versa?