CEikTextListBox ??

Login to reply to this topic.
Thu, 2005-05-19 13:22
Anonymous
Forum posts: 2018
Hello,
i have two question for the CEikTextListBox.

1. I want to select a item directly with the code - is it possible ?

2. If i tip on a item, i want to handel this event. What must i add to handle this event with the HandleCommandL ??

Thanks for helping... Michael

Tue, 2005-05-24 08:44
Joined: 2004-12-30
Forum posts: 44
Re: CEikTextListBox ??
1- Answer to the first question : U can select an item directly from code by using :

function     : SetCurrentItemIndex()

prototype   : void SetCurrentItemIndex(TInt aItemIndex) const;

Description  : Sets the current item, but does not redraw the list. If the item was not previouly visible it is set to the top item in the view.

Parameters  :TInt aItemIndex  Index of the item to make current.

2- Why U use HandleCommandL? Build a class derived from CEikTextListBox and handle event in HandlePointerEvent() of this class.

Afro

Tue, 2005-05-24 10:17
Joined: 2003-12-05
Forum posts: 607
Re: CEikTextListBox ??
Quote from: neobk
2- Why U use HandleCommandL? Build a class derived from CEikTextListBox and handle event in HandlePointerEvent() of this class.

Even more convenient, set your object to be an observer of the CEikTextListBox object and implement HandleListBoxEventL.
Tue, 2005-05-24 14:54
ivolein (not verified)
Forum posts: 2018
Re: CEikTextListBox ??
Hello,
@1:
I add a new item to the CEikTextListBox with this function:
     m_piDataItemTextArray->AppendL(szDataServiceLabel);
     m_pilboxDataServices->HandleItemAdditionL();
Now i want to to select this item with:
    m_pilboxDataServices->SetCurrentItemIndex(0);
But this doesn't work.

@2:
I have created a subclass called:" class ListBoxHandle : public CEikTextListBox" with the function:
 HandlePointerEventL(const TPointerEvent& aPointerEvent)
But this function wasn't called anyway

Have you an example for point 1 and 2

Thanks... Michael
Tue, 2005-05-24 21:27
ivolein (not verified)
Forum posts: 2018
Re: CEikTextListBox ??
@1... it works now - i have forgotten to set the focus on the list.

But with problem 2 i have still a problem

michael
Wed, 2005-05-25 10:28
Joined: 2004-12-30
Forum posts: 44
Re: CEikTextListBox ??
View that contains the instance of class ListBoxHandle must be added in to stack in class AppUi by using :

function AddToStackL(); Grin like this :AddToStackL( iAppView );

and remember put this line in the destructor of class AppUi

RemoveFromStack( iAppView );  Roll Eyes
Wed, 2005-05-25 10:54
Joined: 2004-05-21
Forum posts: 49
Re: CEikTextListBox ??
Hi

This might be unrelated, but when calling SetCurrentItemIndex on a listbox in a dialog, the item is selected but not scrolled into view. I found a function named SetTopItemIndex, but it didn't help! My listbox might have a couple of hundreds of rows, and I wanted any of them to be pre-selected and visible when the dialog pops up...

BR/Linda
Thu, 2005-05-26 07:35
Joined: 2004-12-30
Forum posts: 44
Re: CEikTextListBox ??
function void ScrollToMakeItemVisible(TInt aItemIndex) const;

will help you. Grin
Mon, 2005-05-30 13:48
ivolein (not verified)
Forum posts: 2018
Re: CEikTextListBox ??
Now i can handle the PointerEventL. With this code-lines i get a message with item i have clicked:
void CDABDataDecoderAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
   CCoeControl::HandlePointerEventL(aPointerEvent);
   if (aPointerEvent.iType==TPointerEvent::EButton1Down && m_pilboxDataServices->View() )
   {
      for(TInt i = m_pilboxDataServices->View()->TopItemIndex(); i <=  m_pilboxDataServices->View()->BottomItemIndex(); i++)
      {
         if( m_pilboxDataServices->View()->ItemIsSelected(i))
         {
            TBuf<20> toWrite;
            _LIT(KFormat1, "select service %d");
            toWrite.Format(KFormat1,i);
            InfoPrint(toWrite,1);
         }
      }
   }
}

But i have always a litte problem... I want only that the InfoPrint was shown, wenn i click on the m_pilboxDataServices.
If i click on the window ,and not in the listbox, the selected item will be printed in the InfoPrint.
How can i check, wether the click was in the listbox or not ?

Thanks.. Michael
Wed, 2005-06-01 17:15
Joined: 2003-12-05
Forum posts: 607
Re: CEikTextListBox ??
Well, since you didn't take a hint of my previous message, here's a sample code to show how easily you could have done this without messing with pointer events...  Wink

First, make your control an observer of listbox:

Code:
class CMyContainer : public CCoeControl,
public MEikListBoxObserver,
public MCoeControlObserver
{
...
// From MEikListBoxObserver
void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType);
...

Then implement the listbox observer interface:

Code:
void CMyContainer::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
{
if((aListBox == iTextListBox) && (aEventType == EEventItemClicked || aEventType == EEventEnterKeyPressed))
{
TInt selected = iTextListBox->CurrentItemIndex();
if (selected >= 0)
{ // Do whatever you want with the selection index.
}
}
}

Also, you have to set your container to be an observer of the listbox (in ConstructL of your container):

Code:
iTextListBox->SetListBoxObserver(this);
iTextListBox->SetObserver(this); // required to get the selection change events too.

The SetObserver is only needed if you also implement the MCoeControlObserver interface.

Now you will get the HandleListBoxEventL called only when the click happened on the listbox. With pointer events, you won't get this event when the user uses the keyboard to scroll and select the item, with this way it does not matter if the user uses the touch display or the keyboard -- both work.

If you also want to know when the selection changes (without actually selecting the item on the list), implement also the MCoeControlObserver interface (otherwise, just don't inherit it):

Code:
void CMyContainer::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
{
if (aControl == iTextListBox && aEventType == EEventStateChanged)
{
// Use the current index to do whatever.
TInt current = iTextListBox->CurrentItemIndex());
}
}
Thu, 2005-06-02 16:14
ivolein (not verified)
Forum posts: 2018
Re: CEikTextListBox ??
thank you... it works now   Smiley Smiley
Wed, 2005-12-07 12:15
Joined: 2005-12-07
Forum posts: 2
Re: CEikTextListBox ??
How about this ? I get error error C2061: syntax error : identifier 'TListBoxEvent'. What i need?
Wed, 2005-12-07 21:36
Joined: 2005-12-07
Forum posts: 2
Re: CEikTextListBox ??
Now its work! I forget include eiklbo.h-file.
  • Login to reply to this topic.