Getting the text of the currently selected list box item
| Thu, 2006-04-13 15:37 | |
|
Hi ,
I need to get the text of the currently selected list box item in a descruiptor. I know we can get the index of the current item selected as follows : Code: iListBox->CurrentItemIndex() ; using the CurrentItemIndex() method.I am using a CAknSingleStyleListBox , how do I get the text of the currently selected item ? Thanks a lot ![]() |
|







Forum posts: 982
MDesCArray* textArray = listBox->Model()->ItemTextArray();
CDesCArray* listBoxItems = static_cast<CDesCArray*>(textArray);
And from here is easy
pirosl
Forum posts: 13
Example ListBox:
TBuf<128> item = (*listBoxItems)[index]; // item = Bill
Press "T" for FindBox in above Example ListBox:
TBuf<128> item = (*listBoxItems)[index]; // item = Bill
Forum posts: 982
pirosl
Forum posts: 13
but... it's read-only. For my project I acutally need to be able to modify the entry (technically not the actual display text, but its icon %d\t\%S).
Is there a way to get the "actual" CurrentItemIndex(), not relative to the current view so I can modify the current item in the list box? Or some other method of achieving a similar result...
TInt aIndex = iListBox->CurrentItemIndex();
MDesCArray* textArray = this->Model()->ItemTextArray();
CDesCArray* listBoxItems = static_cast<CDesCArray*>(textArray);
// Replace Item Icon
TBuf<128> item = (*listBoxItems)[aIndex];
_LIT(KTab, "\t");
_LIT(KNewIcon, "1"); // actually dynamically calculated elsewhere
TInt pos = item.Find(KTab);
item.Replace(0, pos, KNewIcon);
listBoxItems->Delete(aIndex);
listBoxItems->InsertL(aIndex, item);
this->DrawItem(aIndex);
I havn't found anything in the SDK for doing that, other than maybe pulling out the item text and searching for it in the full version listBoxItems... but that wouldn't handle duplicates without getting rediculously nasty by attempting to create some algorithm based on the FindBox's search text, relative index in the FindBox result, and what items were previously selected. *ugg*
Forum posts: 982
pirosl
Forum posts: 13
TPtrC itemBefore = this->Model()->ItemText(aIndex); // itemBefore = "0\tOld"
_LIT(KNewItem, "1\tNEW");
itemBefore.Set(KNewItem); // itemBefore = "1\tNEW"
TPtrC itemAfter = this->Model()->ItemText(aIndex); // itemAfter = "0\tOld" still
Forum posts: 40
did you solve this issue? I have the same problem here.
Thanks
imzadi
Forum posts: 13
TInt CMyClass::GetOriginalIndex(const TInt aVisibleIndex)
{
CAknFilteredTextListBoxModel* model = STATIC_CAST(CAknFilteredTextListBoxModel*, this->Model());
return model->Filter()->FilteredItemIndex(aVisibleIndex);
}
...
_LIT(KNewItem, "1\tNEW"); // Hardcoded example
TInt visibleIndex = this->View()->CurrentItemIndex();
TInt originalIndex = GetOriginalIndex(visibleIndex);
if (originalIndex != KErrNotFound)
{
MDesCArray* textArray = this->Model()->ItemTextArray();
CDesCArray* listBoxItems = static_cast<CDesCArray*>(textArray);
TBuf<128> oldItem = (*listBoxItems)[originalIndex];
listBoxItems->Delete(originalIndex);
listBoxItems->InsertL(originalIndex, KNewItem);
this->DrawDeferred();
}
Forum posts: 40
Thanks
Forum posts: 13
Forum posts: 40
Do you know anything about
class AknListBoxLinesTemplateIf yes Please hellp me.
I need to find out how to use it.
Thanx.