about ListBox selection.......

Login to reply to this topic.
Wed, 2005-08-10 08:04
Joined: 2005-08-04
Forum posts: 27
i have created the ListBox but i cann't nevigate the items using arrow key. my code is given below:



.rss
RESOURCE LISTBOX r_akntalist_single_1 {
   array_id = r_akntalist_item_single1;
   flags = EAknListBoxSelectionList;
   //flags = EAknListBoxMarkableList;
}
RESOURCE ARRAY r_akntalist_item_single1 {
   items =
   {
      LBUF { txt = "1\tItem1"; },
      LBUF { txt = "2\tItem2"; },
      LBUF { txt = "3\tItem3"; },
      LBUF { txt = "4\tItem4";}
   };     
}


mycontainer.cpp
void mycontainer::ConstructL(const TRect& aRect)
   {
   CreateWindowL();
   TInt resourceId = R_AKNTALIST_SINGLE_1;
   iListBox = new(ELeave)CAknSingleNumberStyleListBox();
   iListBox->SetContainerWindowL( *this);
   TResourceReader reader;
   CEikonEnv::Static()->CreateResourceReaderLC(reader, resourceId);
   iListBox->ConstructFromResourceL( reader );
   CleanupStack::PopAndDestroy(); // resource stuffs.   
   SizeChanged();
   iListBox->ActivateL();
   DrawNow();
   SetRect(aRect);
   ActivateL();
   }

TInt mycontainer::CountComponentControls() const
   {
   return 1;
   }

CCoeControl* mycontainer::ComponentControl(TInt aIndex) const
   {
   switch(aIndex)
   {
      case 0: return iListBox;
      default: return NULL;
   }
   }

void mycontainer::SizeChanged()
   {
   iListBox->SetExtent (TPoint(0,0), iListBox->MinimumSize());   
   }


it is displaying the Items and select the Item1. i want to go Item2 or Item3........ but i cann't

i am beginner. i am just learning. pls show some ways to do this

thanks

bashar  


Wed, 2005-08-10 08:15
Joined: 2003-04-01
Forum posts: 142
Re: about ListBox selection.......
I think you forgot to forward the keyevents to your listbox in your offerkeyevent function.

yucca
Wed, 2005-08-10 08:34
Joined: 2005-08-04
Forum posts: 27
Re: about ListBox selection.......
thanks pls tell me how?

pls specify

thks
bashar
Wed, 2005-08-10 08:40
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 2006
Re: about ListBox selection.......
Look how the OfferKeyEventL function is managed in a listbox example code.
You won't learn if you expect people to post the exact snippet of code that you require.

Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

Wed, 2005-08-10 12:22
Joined: 2005-08-04
Forum posts: 27
Re: about ListBox selection.......
hi all

thanks i have solved the problem now i can navigate the ListBox items

now i want to know how can i go in "Item 1"(one of ListBox item) by pressing ok

anybody can help?

thanks

bashar
Wed, 2005-08-10 12:44
Joined: 2004-12-03
Forum posts: 192
Re: about ListBox selection.......
Quote from: eric
You won't learn if you expect people to post the exact snippet of code that you require.
unfortunately, most of newbies just want the sources :\
Wed, 2005-08-10 13:13
Joined: 2005-08-04
Forum posts: 27
Re: about ListBox selection.......
thanks.

sorry i cann't agree with u. i want some suggestions not source code. if u know the right way then just inform me about that. thats all.

anyway thanks again for your attention

bashar
Wed, 2005-08-10 14:30
Joined: 2004-12-03
Forum posts: 192
Re: about ListBox selection.......
Code:
TKeyResponse mycontainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
return iListBox->OfferKeyEventL(aKeyEvent, aType);
}
and don't forget to set focus to your listbox in ConstructL
Wed, 2005-08-10 16:32
Joined: 2005-03-04
Forum posts: 176
Re: about ListBox selection.......
>now i want to know how can i go in "Item 1"(one of ListBox item) by pressing ok

Code:
/**
* Called by the framework whenever a list event occurs for which this container
* is an observer.
* @param aListBoxEvent The type of event which occured
*
*/
void CMyContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aListBoxEvent)
{

// if the Select Key has been pressed
if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) || (aListBoxEvent == MEikListBoxObserver::EEventItemClicked)) {
if (iMyListBox) {
                                // Do something with ...
//...((*iMyList)[iMyListBox->CurrentItemIndex()]);
}
}
}
}

regards;
CG
Thu, 2005-08-11 10:15
Joined: 2005-08-04
Forum posts: 27
Re: about ListBox selection.......
thanks CG

previously i used resource file for the ListBox now i want without resource. i have changed my code but it gives linking error

how can i solve

code:

iListBox = new (ELeave) CAknSingleNumberStyleListBox();   
   iListBox->SetContainerWindowL(*this);
   iListBox->ConstructL(this,EAknListBoxSelectionList);

   CDesC16Array* array = new (ELeave) CDesCArray(5 ); //here gives the error message
   
   CleanupStack::PushL(array);
   array->AppendL(_L("1\tItem1"));
   array->AppendL(_L("2\tItem2"));
   array->AppendL(_L("3\tItem3"));
   array->AppendL(_L("4\tItem4"));
   array->AppendL(_L("5\tItem5"));
   CleanupStack::Pop();
   iListBox->Model()->SetItemTextArray(array);


    SetRect(aRect);
    ActivateL();

where is the problem?

i have included

#include "MyFirstAppContainer.h"
#include <eiklabel.h>  // for example label control
#include <aknlists.h>
#include <badesca.h>

pls someone give the response

thks

bashar
Thu, 2005-08-11 10:25
Joined: 2005-03-04
Forum posts: 176
Re: about ListBox selection.......
The class is abstract and cannot be instantiated.  Wink
Try  CDesCArrayFlat instead;

Bye;
CG
Fri, 2005-08-12 05:27
Joined: 2005-08-04
Forum posts: 27
Re: about ListBox selection.......
thanks CG

i have solved that problem

bashar
Wed, 2008-02-06 14:34
Joined: 2007-10-26
Forum posts: 36
Re: about ListBox selection.......

Mr Bashar. please expalin me what will be the code in Ui.cpp. Iam very much canfused. My application is getting closed (program closed) as we run the application in the emeulator.

where I have went wrong?

  • Login to reply to this topic.