Changing the Direction of ListBox

Login to reply to this topic.
Tue, 2007-09-11 13:34
Joined: 2007-07-09
Forum posts: 40

Hi,
Is there any way to change the direction of listbox from "left-to-right" to "right-to-left"? You know, I use a database of farsi words which I want to show them in order with a list box; the problem is that the words are shown not only left to right, but also in reverse character order.
I had the same problem for Window graphics context and I resolved it by using DrawTextExtended() method but I wonder if there is something similar for listboxes.
Thank you beforehand. Smiling


Thu, 2007-09-13 09:57
Joined: 2006-10-05
Forum posts: 80
Re: Changing the Direction of ListBox

Hi Rostam,

Maybe this can a bit helpful:
iListBox->ItemDrawer()->ColumnData()->SetColumnAlignmentL(1, CGraphicsContext::ERight);

I have checked it, it makes the text in the second column of your list box right aligned.

You can first reverse your entire string and then display it right-aligned.

I hope this is useful.

Sat, 2007-09-15 08:51
Joined: 2007-07-09
Forum posts: 40
Re: Changing the Direction of ListBox

hi jp4symbian,
Thanks for your response. I have defined iListBox as CEikTextListBox (CEikTextListBox* iListBox;). This class dos not have itemDrawer method. Is your iListBox defined as CSettingsListBoxView? How can I use it?
Thanks.

Sat, 2007-09-15 09:35
Joined: 2006-10-05
Forum posts: 80
Re: Changing the Direction of ListBox

Hello Rostam,

I have used CAknSingleNumberStyleListBox. There are many such different types of listboxes that you can use depending on your requirement.

And the implementation can be found in the List Box example in the SDK.

For more information on ListBox, an extremely useful link is:
http://www.newlc.com/article.php3?id_article=136

Sun, 2007-09-16 10:23
Joined: 2007-07-09
Forum posts: 40
Re: Changing the Direction of ListBox

Hi jp4symbian, I wonder why I can not handle listboxes Puzzled I have no compilation error but my application closed when I run it on emulator, Can you mail me a simple application which uses listboxes? My yahoo ID is hojatvaheb. God Bless you. Eye-wink

Mon, 2007-09-17 06:55
Joined: 2006-10-05
Forum posts: 80
Re: Changing the Direction of ListBox

Hi Rostam,

First I need to know which SDK are you working with currently.

If you are working with S60 3rd Edition, then I won't be able to help you. Sad

But if its 2nd Edition, i surely can!!! Smiling

Mon, 2007-09-17 09:04
Joined: 2007-07-09
Forum posts: 40
Re: Changing the Direction of ListBox

I work with 2nd Edition Eye-wink

Mon, 2007-09-17 11:28
Joined: 2006-10-05
Forum posts: 80
Re: Changing the Direction of ListBox

Hi Rostam,

List Boxes are pretty easy things. At present I cannot create a sample due to time constraints. I am sorry about that.. Sad

If you can wait for some time then I can give u a sample....

You can refer this link in your SDK Help:
Developer Guides >> Avkon UI Resources - Listboxes >>Creating and Using Listboxes>>Creating a Numbered Selection Listbox Without a Resource File

You will surely be able to build a List box from this code.
And you can use below code for alignment :-
iListBox->ItemDrawer()->ColumnData()->SetColumnAlignmentL(1, CGraphicsContext::ERight);

Mon, 2007-09-17 11:51
Joined: 2007-07-09
Forum posts: 40
Re: Changing the Direction of ListBox

Hi, I have tired of working with S60 list boxes. I can not see items I read from database with list box but I can see list box items when I define them manually, Look at my code to read from database names:

void CDBMSAppUi::ShowAllRecordsL()
    {
_LIT(KAllRecords,"");
CDesCArrayFlat* Records = iDatabase->GetAllRecordsL();
CleanupStack::PushL(Records);
CDesCArrayFlat* names = NamesArrayL(Records);
CleanupStack::PushL(names);
ChangeViewL(EListView); // construct the listbox view
iListboxView->SetCaptionL(KAllRecords);
CleanupStack::Pop(names);
iListboxView->SetListItemsL(names); // Takes ownership
CleanupStack::PopAndDestroy(Records);
    }

And here is SetListItemsL:
void CDBMSListboxView::SetListItemsL(CDesCArrayFlat* aNewItems)
    {
CTextListBoxModel* model = iListBox2->Model();
model->SetItemTextArray(aNewItems);
// Set ListBox model responsible for deleting the listItems array
model->SetOwnershipType( ELbmOwnsItemArray );
iListBox2->HandleItemAdditionL();//iListBox2 = new(ELeave)CAknDoubleStyleListBox ();
if(aNewItems->Count()>0)
{
        // Select the first item, if there is one.
iListBox2->SetCurrentItemIndexAndDraw(0);
        }

But this code works fine:
void CDBMSListboxView::SetListItemsL(CDesCArrayFlat* aNewItems)
    {
/*…reading from database…*/
CDesCArrayFlat *itemList = new (ELeave) CDesCArrayFlat(10);
itemList->AppendL(_L("\t \x062A\x0644\x0641\x0646\x0647\x0627\x06CC \t\t"));
itemList->AppendL(_L("\tSecond item\t\t"));
// set items and ownership
iListBox2->Model()->SetItemTextArray(itemList);
iListBox2->Model()->SetOwnershipType(ELbmOwnsItemArray);
iListBox2->SetCurrentItemIndex(0);
iListBox2->SetFocus(ETrue);
iListBox2->HandleItemAdditionL();
    }

Thanks.

Mon, 2007-09-17 12:31
Joined: 2006-10-05
Forum posts: 80
Re: Changing the Direction of ListBox

Are you not having a separate Container class for your List Box?

I have loaded my List Box from database just the way you have done except that I have separate view and container classes.

My SetListItemsL() function gets called in the DoActivateL() function of the View class; after Container object is created and constructed.

Moreover you can also add following highlighted lines after list box is loaded:

iListBox->HandleItemAdditionL();

iListBoxEntry->ActivateL();
DrawDeferred();

iListBox->SetCurrentItemIndex(0);

Mon, 2007-09-17 12:57
Joined: 2007-07-09
Forum posts: 40
Re: Changing the Direction of ListBox

Is there anything related to the format of data in listboxes?! You know when I use" \t Data\t\t", it works; but when I read database items, it does not.
Special Thanks to jp4symbian.

Mon, 2007-09-17 13:13
Joined: 2006-10-05
Forum posts: 80
Re: Changing the Direction of ListBox


Oh yes my dear, definitely the format matters!!!!!!!!! I was assuming that you know that!

The format of the data depends on the kind of listbox you are using... You need to format your data before displaying it in the list box.

For e.g. in CAknSingleStyleListBox, data format is "\t%S\t\t"

For CAknSingleNumberStyleListBox, data format is "%d\t%S\t\t" and so on...............

Did you check out following link:
http://www.newlc.com/article.php3?id_article=234

(It can be navigated from the link that i gave u earlier in this post. It lists out almost all kinds of list boxes. Make sure you see the entire tutorial of listboxes which can be reached through the above link)

All the best! Eye-wink

Mon, 2007-09-17 13:57
Joined: 2007-07-09
Forum posts: 40
Re: Changing the Direction of ListBox

How can I change the format of data which is read from database before being displayed? I have a database of farsi words, When I debug my program, I can see that the data is in Unicode form, for example this is a name read from database:
L"\x0633\x0631\x0631\x0633\x06CC\x062F"
Should this name reformatted to L"\t\x0633\x0631\x0631\x0633\x06CC\x062F\t\t" ?I'm not familiar with text processing functions of s60.
Thanks.

Mon, 2007-09-17 14:48
Joined: 2006-10-05
Forum posts: 80
Re: Changing the Direction of ListBox

hi rostam,

I have never worked with Unicode characters so don't know how to manipulate them.
If you can very well display these characters on the screen then you can use the FormatL() function in descriptors (TDes16/TDes8 class) to format your database data.

Just put your data in a descriptor and format it according to the list box that you are using.

For formatting descriptors, go through the following link in your SDK help:
» Developer Library » API Reference » C++ API reference » Descriptors » Using TDes16 >> Formatting text

I suggest first you try displaying simple English strings in your List Box to understand the basics. The you can go ahead with your Unicode characters and alignment.

And don't forget to study descriptors well, it is an extremely important part of Symbian.

Tue, 2007-09-18 10:32
Joined: 2007-07-09
Forum posts: 40
Re: Changing the Direction of ListBox

Thanks jp4symbian, Now I feel a bit better about s60 listboxes, I use the following code to format my data:

TPtrC16 sourceRow;
            TBufC16<16> str(sourceRow);
            TBuf<256> result1;
        _LIT16(temp,"\t");
             CDesCArrayFlat *itemList = new (ELeave) CDesCArrayFlat(10);
         for(TInt i=0; i<aNewItems->MdcaCount(); i++)
            {
               sourceRow.Set(aNewItems->MdcaPoint(i));
               result1=sourceRow.Mid(0);
               result1.Insert(0,temp);
              itemList->AppendL(result1);
        }
        iListBox2->Model()->SetItemTextArray(itemList);//LINE 119
        iListBox2->Model()->SetOwnershipType(ELbmOwnsItemArray);// LINE 120
        iListBox2->SetCurrentItemIndex(0);
        iListBox2->SetFocus(ETrue);
        iListBox2->HandleItemAdditionL();
        iListBox2->ActivateL();

Smiling
result1 has a justify method ehich can be used to change the alignment of data, but it has 4 parameters which I wonder how I can use them,
another thing is that I can not use any listbox except CAknDoubleStyleListBox unless I get error message, for example if I use CAknSingleStyleListBox I get this error message:
Undefined symbol: 'class CTextListBoxModel * CEikColumnListBox::Model(void) const (?Model@CEikColumnListBox@@QBEPAVCTextListBoxModel@@XZ)' referenced from 'void CDBMSListboxView::SetListItemsL(class CDesC16ArrayFlat *) (?SetListItemsL@CDBMSListboxView@@QAEXPAVCDesC16ArrayFlat@@@Z)' in DBMSListboxView.cpp:119 referenced from 'void CDBMSListboxView::SetListItemsL(class CDesC16ArrayFlat *) (?SetListItemsL@CDBMSListboxView@@QAEXPAVCDesC16ArrayFlat@@@Z)' in DBMSListboxView.cpp:120 referenced from 'int CDBMSListboxView::GetSelectedItem(class TDes16 &) const (?GetSelectedItem@CDBMSListboxView@@QBEHAAVTDes16@@@Z)' in DBMSListboxView.cpp:255

I have specified line 119 , 120 in my code.
Thanks.

Tue, 2007-09-18 11:19
Joined: 2006-10-05
Forum posts: 80
Re: Changing the Direction of ListBox

Hi Rostam,

I think there is some misunderstanding. There is no difference in using CAknSingleStyleListBox or CAknDoubleStyleListBox as long as the following lines are concerned:
iListBox2->Model()->SetItemTextArray(itemList);
iListBox2->Model()->SetOwnershipType(ELbmOwnsItemArray);

Maybe there is some change that you have forgotten to do when you use CAknSingleStyleListBox instead of CAknDoubleStyleListBox. Make sure you have made all necessary changes in header file n all.

Also I can tell you a better way to format.
Suppose if you are using CAknSingleStyleListBox.

_LIT(KListFormat,"_LIT(KListItemFormat, "\t%S\t\t"); // Initiliaze the list format of the list you are using/b]
_LIT(KListItem,"Item1");

TBuf<256> item(KListItem);
TBuf<256> insertString;

// Format the data
[b]insertString.Format(KListItemFormat,&item); // Use the format function
iItemArray = static_cast(iListBox->Model()->ItemTextArray());

iItemArray ->AppendL(listboxItems++, insertString);
iListBox->HandleItemAdditionL();
iListBox->SetCurrentItemIndex(0);
DrawDeferred();

  • Login to reply to this topic.