×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    53

    how to compare a listbox item with a string

    hii all...

    how to i convert from TPtrC16 to TDesc16? I kno TPtrC16 inherits TDesc16 and a simple type cast should solve the problem.

    I am retrieving the Category from the database as iexpTableItem.iexpCat which is a TBuf16.

    I wanna compare it with a list box item using itemArray->MdcaPoint(i), which is of type TPtrC16.

    For comparison CODE USED is:

    iexpTableItem.iexpCat.Compare(itemArray->MdcaPoint(i)
    IS THIS RIGHT???

    i also tried

    iexpTableItem.iexpCat.Compare((TDesC16&)itemArray->MdcaPoint(i))
    this also doesnt work..
    plz reply...thanx!

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,174

    Re: how to compare a listbox item with a string

    that should work, so have you checked that the buffers are actually same ?

  3. #3
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: how to compare a listbox item with a string

    Quote Originally Posted by joteddy123 View Post
    hii all...

    how to i convert from TPtrC16 to TDesc16? I kno TPtrC16 inherits TDesc16 and a simple type cast should solve the problem.

    I am retrieving the Category from the database as iexpTableItem.iexpCat which is a TBuf16.

    I wanna compare it with a list box item using itemArray->MdcaPoint(i), which is of type TPtrC16.

    For comparison CODE USED is:

    iexpTableItem.iexpCat.Compare(itemArray->MdcaPoint(i)
    IS THIS RIGHT???

    i also tried

    iexpTableItem.iexpCat.Compare((TDesC16&)itemArray->MdcaPoint(i))
    this also doesnt work..
    plz reply...thanx!

    What is error??? past your error here.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: how to compare a listbox item with a string

    Remember that the items in the itemarray are formatted in a special way (at a minimum, it contains a tabulator as its first character).
    Anyway, are you sure about that comparing strings is necessary? What do you want to achieve exactly? Remember that you are the one who builds both arrays, so it could be more effective to store relations when creating the itemarray.

  5. #5
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    53

    Re: how to compare a listbox item with a string

    hii...i have a database storing expense details. I want to retrieve and print distinct category names (which exist in the database may be more than once) in a list box. For this, the logic i have used is...i print the cateory of teh first record in the list box automatically. Then, from next record onwards, before appending the category name to the list, i compare teh category name retrieved from the database with all the list items present. If the category already exists in the list, i go ahead to retrieve the category in the next database record, else print category name in the list...
    here is the code thats not running...can u help me find my mistake???
    thank u!!

    void CExpListBox4::LoadCatListL()
    {
    CexpDatabase* expDb = CexpDatabase::NewL();
    TexpTableItem iexpTableItem;
    CleanupStack::PushL(expDb);

    TInt count = 0;
    expDb->GetexpTableCountL(count);

    if(count==0)
    {
    CleanupStack::PopAndDestroy();
    return;
    }

    TBool first = expDb->GetexpTableFirstRecordL(iexpTableItem);
    TBool next = EFalse;
    TBuf<32> aBuffer;
    TInt i = 1;


    if(first)
    {
    CAknFilteredTextListBoxModel* filteredModel = static_cast< CAknFilteredTextListBoxModel* >( iListBox->Model() );

    CDesCArray* itemArray = static_cast< CDesCArray* > (filteredModel->ItemTextArray() );

    itemArray->Reset();

    _LIT ( KStringHeader, "\t%S" );
    aBuffer.Format( KStringHeader(), &iexpTableItem.iexpCat );
    itemArray->AppendL(aBuffer);
    iListBox->HandleItemAdditionL();

    _LIT(KTotal , "Food");
    TBuf<16> Buf ;
    Buf=KTotal;
    //Buf=(TDesC16&)itemArray->MdcaPoint(1);

    do
    {
    TInt ctr=itemArray->Count();

    for(TInt i=1;i<=ctr;i++)
    {
    if(iexpTableItem.iexpCat.Compare(itemArray->MdcaPoint(i)) == 0)

    {
    _LIT ( KStringHeader, "\t%S" );
    aBuffer.Format( KStringHeader(), &iexpTableItem.iexpCat );
    itemArray->AppendL(aBuffer);
    iListBox->HandleItemAdditionL();
    break;
    }
    //else
    //break;
    }
    next = expDb->GetexpTableNextRecordL(iexpTableItem);

    }
    while(next);

    CleanupStack::PopAndDestroy(expDb);
    }
    else
    CleanupStack::PopAndDestroy(expDb);
    }


    The above line has the error.
    i also tried
    if(iexpTableItem.iexpCat.Compare((TDesC&)itemArray->MdcaPoint(i)) == 0)

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: how to compare a listbox item with a string

    Enable error messages: http://wiki.forum.nokia.com/index.ph...ded_panic_code, then you will find it quickly.

  7. #7
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    53

    Re: how to compare a listbox item with a string

    foumd it...thanks!

Similar Threads

  1. how to compare the list items with a string
    By manojkumar.m in forum Symbian
    Replies: 7
    Last Post: 2008-11-18, 05:32
  2. string format in listbox
    By john_malloc in forum Symbian
    Replies: 3
    Last Post: 2007-03-06, 13:36
  3. getting the item from listbox
    By srkreddy999 in forum Symbian User Interface
    Replies: 2
    Last Post: 2005-10-20, 13:23
  4. How to Highlight item in ListBox.........
    By platinnum in forum Symbian
    Replies: 1
    Last Post: 2005-05-19, 14:25
  5. double item with large graphic listbox
    By oiram1 in forum Symbian User Interface
    Replies: 1
    Last Post: 2003-06-10, 02:03

Posting Permissions

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