hi all,
I have created a list box in my container, now what i want is to update ( add or remove) the items from the list box on command from Appui,
Please ignore the code of label it already handled and working...
Here is my code for Container..
*********************************************************
void CIMSI_testContainer::ConstructL(const TRect& aRect,bool showlist)
{
CreateWindowL();
Expired = showlist;
if(Expired)
{
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
iLabel->SetTextL( _L("") );
iToDoLabel = new (ELeave) CEikLabel;
iToDoLabel->SetContainerWindowL( *this );
iToDoLabel->SetTextL( _L("") );
}
else
{
//iItemList = new (ELeave) CAknSettingItemList;
iItemList = new (ELeave) CAknSingleStyleListBox();
iItemList->SetContainerWindowL(*this);
iItemList->SetMopParent(this);
//EAknListBoxSelectionList();
//iItemList->ConstructFromResourceL(R_ENTRY_SETTINGS_LIST);
iItemList->ConstructL(this,EAknListBoxSelectionList);
LoadListL();
iItemList->MakeVisible(true);
iItemList->SetRect(aRect);
iItemList->ActivateL();
iItemList->DrawNow();
}
// Set the windows size
SetRect(aRect);
// Activate the window, which makes it ready to be drawn
ActivateL();
}
// Destructor
CIMSI_testContainer::~CIMSI_testContainer()
{
if(Expired)
{
delete iLabel;
delete iToDoLabel;
}
else
delete iItemList;
}
// ---------------------------------------------------------
// CIMSI_testContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CIMSI_testContainer::SizeChanged()
{
// TODO: Add here control resize code etc.
if(Expired)
{
iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
iToDoLabel->SetExtent( TPoint(10,100), iToDoLabel->MinimumSize() );
}
else
{
// if not include this line then the list box is shown awkward.
iItemList->SetRect( Rect() ); // vasant :Sets rectangle of listbox.
}
}
// ---------------------------------------------------------
// CIMSI_testContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CIMSI_testContainer::CountComponentControls() const
{
// return 2; // return nbr of controls inside this container
if(Expired)
{
return 2; // return nbr of controls inside this container
}
else
{
TInt count = 0;
if (iItemList)
count++;
return count;
}
}
// ---------------------------------------------------------
// CIMSI_testContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CIMSI_testContainer::ComponentControl(TInt aIndex) const
{
if(Expired)
{
switch ( aIndex )
{
case 0:
return iLabel;
case 1:
return iToDoLabel;
default:
return NULL;
}
}
else
return iItemList;
}
// ---------------------------------------------------------
// CIMSI_testContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CIMSI_testContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
// TODO: Add your drawing code here
// example code...
if (Expired)
{
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGray );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
gc.Clear( Rect() );
const CFont* font = LatinBold12();
gc.UseFont( font );
gc.DrawText( _L("Trail Expired"), TPoint( 10,20 ) );
gc.DrawText( _L("Please Register"), TPoint( 10,40 ) );
}
else
{
TRect rect = Rect();
// Clears the screen
gc.Clear(rect);
}
}
// ---------------------------------------------------------
// CIMSI_testContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CIMSI_testContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
void CIMSI_testContainer::LoadListL()
{
RFs aFs;
RFile file;
aFs.Connect();
//TBuf8<200> Temp8;
TBuf8<20> IMSIno;
TBuf16<30> Temp16;
TBuf16<20> TempC16;
array = new (ELeave) CDesCArrayFlat(11);
TInt cnt=0,i=0;
TInt iErr = file.Open(aFs,KIMSIFile,EFileRead);
if(iErr == KErrNone)
{
file.Read(Temp8);
_LIT8(CR,"|");
TInt index = 0;
array->AppendL(_L("\t- White SIM List -"));
while(Temp8.Length() > 14)
{
TInt index = Temp8.Find(CR);
if(index > 0)
{
IMSIno.Copy(Temp8.Mid(0,index ));
Temp8.Delete(0,Temp8.Find(CR)+1);
TempC16.Copy(IMSIno);
//Temp16.Format(_L("%d\t%S"),++cnt,&TempC16);
Temp16.Format(_L("\t%S"),&TempC16);
array->AppendL(Temp16);
}
else
break;
}
//iItemList->Model()->SetItemTextArray(array);
}
else
{
array->AppendL(_L("\t- No White SIM -"));
}
iItemList->Model()->SetItemTextArray(array);
file.Close();
aFs.Close();
}
// ----------------------------------------------------
// CDynamicSettingListAppView::StoreSettingsL()
// Stores the settings of the setting list.
// ----------------------------------------------------
//
void CIMSI_testContainer::StoreSettingsL()
{
/* iItemList->StoreSettingsL();*/
}
// vasant : added explicitly for scrolling facility.
TKeyResponse CIMSI_testContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,
TEventCode aType )
{
if(aType != EEventKey)
{
return EKeyWasNotConsumed;
}
else if(iItemList)
{
return iItemList->OfferKeyEventL( aKeyEvent, aType );
}
else
{
return EKeyWasNotConsumed;
}
}
*********************************************************
so what i want is that when a user presses AddItem command i should be able to add the item and display in the list box , i am not able to find any good example, the example given in the sdk is far more complicated and confusing.
Thanks waiting for replies.
-vasant




