extra data with listbox item

Login to reply to this topic.
Wed, 2005-04-27 10:27
Joined: 2005-02-21
Forum posts: 47
Hi,
 simple and, seems to me, should be a common question but haven't found an explanation or example of yet.

My purpose is to have some data associated with a listbox item (id, pointer, whatever). You know, from windows API the one can remember that you can set some void* with listbox or something ... that's a different approach with Symbian here, I somewhat know.

What I've done to get this is that I've implemented my own class from MListBoxModel and MTextListBoxModel (because I want a "standard" text displayed still). Implemented necessary functions.

I'm bit in trouble with correctly associating my model with listbox. I've derived yet another my own class for listbox - from CAknDoubleStyleListBox class because I found no other method of setting my own model into.
---
void CMyListBox::ConstructL( CCoeControl* aParent )
{
   iModel = (MTextListBoxModel*)new (ELeave) CMyListBoxModel;

   iListItemDrawer = new (ELeave) CTextListItemDrawer( (CTextListBoxModel*)iModel, NULL );
   CleanupStack::PushL(iListItemDrawer);
   CEikListBox::ConstructL( iModel, iListItemDrawer, aParent );
   CleanupStack::Pop(); // drawer
}
---

What I do not understand exaclty what the CEikListBox::ConstructL does. Because I see with debugger like it creates it's own iModel and iListItemDrawer anyway ... what's the point of those arguments then? And when I call listbox->Model() and cast it to my class (as I expect to be it mine), it crasehes. And not worth to mention that noone calls my inherited NumberOfItems() and ItemText.

Where am I wrong? Is it a correct approach of implementing such a small thing as wanting to have my own data associated with a single listbox item?

if you read up to this - thanks Smiley

rgds,
 Ahti.

Wed, 2005-04-27 19:23
Joined: 2005-02-21
Forum posts: 47
extra data with listbox item
Ok, I'll have to answer it by myself ... just for a record and for information to others.

My approach above was not quite correct. I don't why it shouldn't work though but anyway.

One does not have to inherit model but instead provide model with the data implementing MDesCArray. Easy enough and elegant actually.

Why it's not used in any of samples provided?

Ahti.
  • Login to reply to this topic.