×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Oct 2003
    Location
    Germany, Karlsruhe
    Posts
    79

    Getting text from items of ListBox

    Hello all !

    I created a ListBox.
    I would like now to get the text of my current selected item.
    This doesn´t work:

    TBufC<20> CLISTSContainer::GetContentCurrentItem()
    {
    TInt currentItem = iListBox->CurrentItemIndex();
    MDesCArray* itemList = iListBox->Model()->ItemTextArray();
    TBufC<20> str;
    return itemList[currentItem];
    }

    May I have some help please ?

    Thanx a lot !!!

    Fabrice

  2. #2
    Registered User
    Join Date
    Oct 2003
    Posts
    9

    Try this!

    TBufC<20> CLISTSContainer::GetContentCurrentItem()

    {

    TInt currentItem = iListBox->CurrentItemIndex();

    MDesCArray* itemList = iListBox->Model()->ItemTextArray();

    CDesCArray* itemArray = (CDesCArray*) itemList;

    TBufC<20> str;

    return itemArray[currentItem];
    }

  3. #3
    Regular Contributor
    Join Date
    Oct 2003
    Location
    Germany, Karlsruhe
    Posts
    79

    Thanx but ...

    Thanx, I got the idea and I did this :

    TBufC<32> str;
    TInt currentItem = iListBox->CurrentItemIndex();
    MDesCArray* itemList = iListBox->Model()->ItemTextArray();
    CDesCArray* itemArray = (CDesCArray*) itemList;
    str = (TBufC<32>) itemArray[currentItem];
    return str;

    But the line str = (TBufC<32>) itemArray[currentItem];
    gives an error -> type cast' : cannot convert from 'class CDesC16Array' to 'class TBufC<32>'

    I don&acute;t get it cause I&acute;m actually willing to get an item (currentItem) of this array, which should be a TBufC !!
    Cf: Adding an item to my listbox is like that :
    _LIT(KProv,"X\tSensor X \tx1234"); // Constant Name generated
    TBufC<32> str(KProv);

    CDesCArray* array=static_cast<CDesCArray*>(iListBox->Model()->ItemTextArray());
    array->AppendL(str);
    iListBox->HandleItemAdditionL();

    Thanx again !

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166
    Hi

    The most efective way of getting stuff from listbox would be to do something like this:

    //--start of code
    TBool GetFromListBox(TDes& aText,Tint aItem, TInt aField)
    {
    TBool RetVal = EFalse;
    if(!iListBox)
    return RetVal;

    MDesCArray* itemList = iListBox->Model()->ItemTextArray();

    if(itemList->MdcaCount() > aItem)
    {
    TPtrC Item,hjlp;
    Item.Set(itemList->MdcaPoint(aItem));

    if(KErrNone == TextUtils::ColumnText(hjlp,aField,&Item))
    {
    aText.Copy(hjlp);
    RetVal = ETrue;
    }
    }

    return RetVal;
    }
    //--end of code

    yucca

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    if(iListBox)
    {
    returnValue = iListBox->CurrentItemIndex();
    iAvkonAppUi->RemoveFromStack(iListBox);
    delete iListBox;
    //delete iAppEngine;
    //iAppEngine = NULL;
    iListBox=NULL;
    }

  6. #6
    Regular Contributor
    Join Date
    Oct 2003
    Location
    Germany, Karlsruhe
    Posts
    79
    Hey dacx ... Why do u wanna kill my nice littel ListBox ?

    Thanx for your help symbianyucca !!! I try this now ...


    Best Regards,

    Fabrice

  7. #7
    Regular Contributor
    Join Date
    Oct 2003
    Location
    Germany, Karlsruhe
    Posts
    79
    Me again ...
    aText.Copy() doesn&acute;t work ...
    May I use somethin like aText(hjlp) ?

    Thanx again ... sorry to bother you that much !

  8. #8
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166
    Hi

    Why doesn't it work ? what happens ?

    Anyway Try to understand that this is C++, which is OBJECT ORIENTED language, meaning that all things that you use are objects, which you use by using the functions of them, very simple and easy. So just forget coding like aText(hjlp), it'll make your life a lot easier..

    In case you don't get something working, go and read the SDK decumentations for other possible function in that class which you could use to achieve your goals.

    yucca

  9. #9
    Regular Contributor
    Join Date
    Oct 2003
    Location
    Germany, Karlsruhe
    Posts
    79
    I&acute;ve seen the description of this class and there wasn&acute;t any Copy() or something like that ...

    I did this :
    TBufC<32> str(hjlp);
    aText= str;

    Is it bad again ,-) ?

    Thanx a lot, I appreciate your help ...

  10. #10
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166
    Hi

    I would suggest you to get one of the available Symbian books and read it from cover to cover.

    Basically you should get your self familiar with the naming convention used in symbian, learning it could really save your time.

    Basically when you see C in descriptor name like TPtrC TBufC etc. it means that the object is constant type, non-constant types dont have the C, like Tptr, TBuf etc.. ond of course you can't modify constant object so there is no Copy()..

    yucca

  11. #11
    Regular Contributor
    Join Date
    Oct 2003
    Location
    Germany, Karlsruhe
    Posts
    79
    Yeah yeah ... exactly ... I found by myself !!!
    Thanx a lot ... I see clearly what are those descriptors now !!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×