scroll bar in listbox

Login to reply to this topic.
Thu, 2005-08-04 05:52
Joined: 2005-07-28
Forum posts: 14
Hi,

I am new to Symbian development. I am trying to create a listbox with a vertical scroll bar. I have created the listbox and the focus can be changed with the movement of keys. But the scroll bar is not visible. I am calling SetScrollBarVisibilityL with vertical scroll bar visibility as EAuto. Even EOn doesnt make it visible. Here is my container:

// HelloWorldBasicContainer.cpp

// Class implemented CHelloWorldBasicContainer
#include <aknlists.h>
#include <akntabgrp.h>
#include <coemain.h>

#include "HelloWorldBasicContainer.h"

CHelloWorldBasicContainer* CHelloWorldBasicContainer::NewL(const TRect& aRect)
   {
   CHelloWorldBasicContainer* self = CHelloWorldBasicContainer::NewLC(aRect);
   CleanupStack::Pop(self);
   return self;
   }
CHelloWorldBasicContainer* CHelloWorldBasicContainer::NewLC(const TRect& aRect)
   {
   CHelloWorldBasicContainer* self = new (ELeave) CHelloWorldBasicContainer;
   CleanupStack::PushL(self);
   self->ConstructL(aRect);
   return self;
   }
// ----------------------------------------------------------------------------
// void CHelloWorldBasicContainer::CHelloWorldBasicContainer()
// Class constructor.
// ----------------------------------------------------------------------------
//
CHelloWorldBasicContainer::CHelloWorldBasicContainer()
   {
   }
// ----------------------------------------------------------------------------
// void CHelloWorldBasicContainer::~CHelloWorldBasicContainer()
// Virtual destructor.
// ----------------------------------------------------------------------------
//
CHelloWorldBasicContainer::~CHelloWorldBasicContainer()
   {
   delete iListBox;
   }

// ----------------------------------------------------------------------------
// void CHelloWorldBasicContainer::ConstructL(const TRect aRect)
// Second phase construction.
// ----------------------------------------------------------------------------
//
void CHelloWorldBasicContainer::ConstructL(const TRect aRect)
   {
   CreateWindowL();
   CreateListL();
   SetRect(aRect);
   ActivateL();
   }

// ----------------------------------------------------------------------------
// TInt CHelloWorldBasicContainer::CountComponentControls() const
// Gets the number of controls contained in a compound control.
// ----------------------------------------------------------------------------
//
TInt CHelloWorldBasicContainer::CountComponentControls() const
   {
   return 1;
   }

// ----------------------------------------------------------------------------
// CCoeControl* CHelloWorldBasicContainer::ComponentControl(TInt /* aIndex */) const
// Gets the specified component of a compound control.
// ----------------------------------------------------------------------------
//
CCoeControl* CHelloWorldBasicContainer::ComponentControl(TInt /* aIndex */) const
   {
   return iListBox;
   }

// ----------------------------------------------------------------------------
// void CHelloWorldBasicContainer::Draw( const TRect& aRect ) const
// Fills the window's rectangle.
// ----------------------------------------------------------------------------
//
void CHelloWorldBasicContainer::Draw(const TRect& aRect)const
   {
   CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbWhite);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
   }
// ----------------------------------------------------------------------------
// void CHelloWorldBasicContainer::HandleListBoxEventL( CEikListBox*,
//  TListBoxEvent )
// Handles listbox event.
// ----------------------------------------------------------------------------
void CHelloWorldBasicContainer::HandleListBoxEventL(
   CEikListBox* /*aListBox*/,
   TListBoxEvent aEventType)
   {
//   if(aEventType == MEikListBoxObserver::EEventEnterKeyPressed)
//      iEikonEnv->InfoMsg(_L("Not Implemented"));
   }

// ----------------------------------------------------------------------------
// void CHelloWorldBasicContainer::CreateListL()
// Creates the list box.
// ----------------------------------------------------------------------------
void CHelloWorldBasicContainer::CreateListL()
   {
   iListBox = new (ELeave) CAknSingleStyleListBox();
   iListBox->SetContainerWindowL(*this);
   TResourceReader reader;
    iEikonEnv->CreateResourceReaderLC(reader, R_MYLISTBOX_SINGLE_1);   
    iListBox->SetListBoxObserver(this);
   iListBox->ConstructFromResourceL(reader);
    iListBox->CreateScrollBarFrameL( ETrue );
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
            CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto );
   CleanupStack::PopAndDestroy();   
   SizeChanged();   
   }
// ---------------------------------------------------------
// void CHelloWorldBasicContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CHelloWorldBasicContainer::SizeChanged()
   {
   // TODO: Add here control resize code etc.
   iListBox->SetExtent(TPoint(0,0), iListBox->MinimumSize());
   }


// ----------------------------------------------------------------------------
// TKeyResponse CHelloWorldBasicContainer::OfferKeyEventL( const TKeyEvent&,
//  TEventCode )
// Handles the key events.
// ----------------------------------------------------------------------------
//
TKeyResponse CHelloWorldBasicContainer::OfferKeyEventL(
                  const TKeyEvent& aKeyEvent,
                  TEventCode aType )
   {
   return iListBox->OfferKeyEventL(aKeyEvent, aType);
   }

I am not able to understand whats going wrong.  Huh Please help.


Thu, 2005-08-04 09:58
Forum Nokia Champion
Joined: 2005-02-16
Forum posts: 45
Re: scroll bar in listbox
Make sure to call SetMopParent() before ConstructL()ing, both in your container and listbox. For instance, call it after SetContainerWindowL():
iListBox->SetMopParent(this);

Same thing when creating the container.
Sun, 2005-08-14 13:31
Joined: 2005-08-04
Forum posts: 32
Re: scroll bar in listbox
I met the same problem.
But this time, i can not see my listbox and i can get my scrollbar.

It is really strange.

I add SetMopParent(),   but the situation did not change!

Any more advice.
  • Login to reply to this topic.