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.
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...
function void ScrollToMakeItemVisible(TInt aItemIndex) const;
will help you.
 
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 ?
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...Â
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()); } }
Forum posts: 44
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.
Forum posts: 607
Even more convenient, set your object to be an observer of the CEikTextListBox object and implement HandleListBoxEventL.
@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
But with problem 2 i have still a problem
michael
Forum posts: 44
function AddToStackL();
and remember put this line in the destructor of class AppUi
RemoveFromStack( iAppView );
Forum posts: 49
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
Forum posts: 44
will help you.
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
Forum posts: 607
First, make your control an observer of listbox:
public MEikListBoxObserver,
public MCoeControlObserver
{
...
// From MEikListBoxObserver
void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType);
...
Then implement the listbox observer interface:
{
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):
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):
{
if (aControl == iTextListBox && aEventType == EEventStateChanged)
{
// Use the current index to do whatever.
TInt current = iTextListBox->CurrentItemIndex());
}
}
Forum posts: 2
Forum posts: 2