×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    7

    Listboxes in views

    Hi!

    I have 2 views and 2 listboxes. If I remove items from listbox in view2, change view to view1 and then change back to view2, removed items is back in the list. How can I make changes permanent? Must I create own class for item arrray or can I save state of listbox somehow?

    Thanks!

  2. #2
    Registered User
    Join Date
    May 2005
    Location
    Indonesia
    Posts
    198

    Re: Listboxes in views

    Hi C64,
    How do you delete the items? Can you paste your code here?
    You don't have to create your own class for listbox arrays, you can use Symbian class, CDesCArray.

    best regards,
    Ronald

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    7

    Re: Listboxes in views

    Creating the listbox. In MyAppContainer2.cpp:

    Code:
    void CMyAppContainer2::CreateListL()
       {
            iMyAppListBox = new (ELeave) CAknSingleStyleListBox();
     	iMyAppListBox->SetContainerWindowL(*this);
    	iMyAppListBox->ConstructL(this, EAknListBoxSelectionList);
       
            CDesCArray* array = new (ELeave) CDesCArrayFlat(5);
            CleanupStack::PushL(array);
            CleanupStack::Pop();
            iMyAppListBox->Model()->SetItemTextArray(array);
        
            AddToList();
       }
    Adding items to list. This is for testing, items will be added from listbox in view1 in ready version.

    Code:
    void CMyAappContainer2::AddToList()
    	{
    	CDesCArray* array = static_cast<CDesCArray*>(iMyAppListBox->Model()->ItemTextArray());
    	array->AppendL(_L("\tItem1"));
    	array->AppendL(_L("\tItem2"));
    	array->AppendL(_L("\tItem3"));
    
            iMyAppListBox->HandleItemAdditionL();
    	}
    Deleting items. This has a litlle bug. If I try to delete last item first, software crashes.

    Code:
    void CMyAppContainer2::RemoveItem()
    	{
    	TInt currentItem(iMyAppListBox->CurrentItemIndex() );
    	CDesCArray* array = static_cast<CDesCArray*>(iMyAppListBox->Model()->ItemTextArray());
    
    	if ( currentItem >= 0 )
    		{
    		array->Delete(currentItem);
    		} 
    	if ( currentItem >= array->Count() )  //Last Item 
    		{
    		currentItem=array->Count();
    		}
    	if ( currentItem >= 0 )
    		{
    		iMyAppListBox->SetCurrentItemIndex(currentItem);
    		}
    	iMyAppListBox->HandleItemRemovalL();
    	
    	}

  4. #4
    Registered User
    Join Date
    Jul 2005
    Location
    Bengaluru, India
    Posts
    747

    Re: Listboxes in views

    Quote Originally Posted by C64
    Deleting items. This has a litlle bug. If I try to delete last item first, software crashes.
    Why didn't you find the error code?

  5. #5
    Regular Contributor
    Join Date
    Apr 2006
    Location
    India
    Posts
    383

    Re: Listboxes in views

    Hi!

    Check this function
    1.
    IMPORT_C void AknListBoxUtils::HandleItemRemovalAndPositionHighlightL ( CEikListBox * aListBox, TInt aValueOfCurrentItemIndexBeforeRemoval,
    TBool aCurrentItemWasRemoved
    ) [static]

    Looks like listbox's HandleItemRemoval does nasty things to currentitemindex and topitemindex. This works better for our purposes.

    2.

    CDesCArray* array = new (ELeave) CDesCArrayFlat(5);
    CleanupStack::PushL(array);
    CleanupStack::Pop();// ??
    iMyAppListBox->Model()->SetItemTextArray(array);

    AddToList();

    I coudnt get u way of coding.

    3.
    Why dont u use SetOwnershipType(ELbmOwnsItemArray) with ur model??

    Check
    Enum TListBoxModelItemArrayOwnership
    TListBoxModelItemArrayOwnership
    Description
    List box item array ownership flags. These values are used to describe whether or not a list box model owns an item array.

    ELbmOwnsItemArray
    The list box model owns the item array, and will delete it in its destructor.


    ELbmDoesNotOwnItemArray
    The model does not own the item array — you must maintain a pointer to it and free it explicitly before your program exits.
    Regards,
    Shilpa Kulkarni

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    7

    Re: Listboxes in views

    Thanks! I think I can solve the problem now.

Similar Threads

  1. Replies: 1
    Last Post: 2004-06-30, 05:32
  2. Problems with forms and views, help needed!
    By _fox in forum Symbian User Interface
    Replies: 0
    Last Post: 2004-06-29, 16:41
  3. got stuck with views
    By gsmartphone in forum Symbian
    Replies: 1
    Last Post: 2004-01-06, 14:47
  4. got stuck with views
    By gsmartphone in forum Symbian User Interface
    Replies: 0
    Last Post: 2004-01-06, 14:15
  5. Switching views on a Dialog-based Views App
    By net314 in forum Symbian User Interface
    Replies: 4
    Last Post: 2003-08-26, 21:05

Posting Permissions

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