×
Namespaces

Variants
Actions

Delete item from a listbox

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: Kavit Patel (16 Oct 2008)
Last edited: hamishwillee (30 May 2013)

The following code snippet explains how to delete an item from the listbox.

To delete an item we need to get the model of the listbox items and then delete the item using HandleItemRemovalAndPositionHighlightL.

Code

Includes:
// for AknListBoxUtils
#include <aknlists.h>
// for CDesCArray
#include <BADESCA.H>
 
Libraries:
avkon.lib
eikctl.lib
eikcoctl.lib
bafl.lib
void DeleteListContent(TInt aIndex)
{
if(iMyViewListbox)
{
//Get the list box items model.
MDesCArray* listArray = iMyViewListbox->Model()->ItemTextArray();
CDesCArray* itemArray = static_cast<CDesCArray*>(listArray);
 
TInt count = itemArray->Count(); //Count the no. of list items.
if(aIndex>=0 && aIndex<count) //Valid Index then delete.
{
itemArray->Delete(aIndex,1);
AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(
iMyViewListbox, aIndex, ETrue);
iMyViewListbox->DrawNow();
}
}
}

We need to pass the listbox pointer, the item index to be deleted and ETrue to remove or EFalse not to, to the HandleItemRemovalAndPositionHighlightL() function which is a static method of AknListBoxUtils class.

After that the DrawNow() needs to be called to draw the listbox with the changes.

This page was last modified on 30 May 2013, at 07:37.
34 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×