| WideStudio Programming Guide | WideStudio Index Table of contents

> ## The tree list

> ### Setting of the items by the method

> Use addItem method to add items to the list which property WSNtype is WS_TREE with a string and position. If the position is omitted, add it to the end of the list. The following program is a sample of adding item to the list. The difference from the list is the items, which are punctuated with a comma. In addition, It is possible to set the nest floor of list items with the setItemValue method. In its argument, set the position of the item and WS_INDENT_LEVEL to the value type, and indent level. If it is omitted, the indent level is 0.

>       setItemValue(pos,WS_INDENT_LEVEL,level);
>       pos = 0,1,2,...,-1(last one)
>       level = 0(top),1,2,3...

> [The tree list]
> The following program is a sample adding item to the list.

>     #include <WScom.h>
>     #include <WSCfunctionList.h>
>     #include <WSCbase.h>
>     //----------------------------------------------------------
>     //Function for the event procedure
>     //----------------------------------------------------------
>     #include <WSCtreeList.h>
>     extern WSCtreeList* newlist_001;
>     void btnep1(WSCbase* object){
>       //Delete all the items of the list.
>       newlist_001->delAll();
>       //Add an item to the last of the list.
>       newlist_001->addItem("item1");
>       newlist_001->setItemValue(-1,WS_INDENT_LEVEL,0);
>       newlist_001->addItem("item2");
>       newlist_001->setItemValue(-1,WS_INDENT_LEVEL,1);
>       newlist_001->addItem("item3");
>       newlist_001->setItemValue(-1,WS_INDENT_LEVEL,2);
>       newlist_001->addItem("item4");
>       newlist_001->setItemValue(-1,WS_INDENT_LEVEL,3);
>       newlist_001->addItem("item5");
>       newlist_001->setItemValue(-1,WS_INDENT_LEVEL,0);
>       newlist_001->addItem("item6");
>       newlist_001->setItemValue(-1,WS_INDENT_LEVEL,1);

>       //Add an item to the specified position of the list.
>       newlist_001->updateList();
>     }
>     static WSCfunctionRegister  op("btnep1",(void*)btnep1);

> As for the point that you should pay attention in tree list, there are no special relational memberships between items at all. And then each item is merely indicated by status appointed indent. So by deleting the item of the upper level, the item of floor following it will not be disappeared. The difference of upper level is only +1. If it is grater than +1, it is adjusted to +1 automatically.

> ### Setting of the items by the property

> The property WSNdata can be used for setting the items of the list, if it is a comparatively little number of the items. In such case, set the property WSNdataSource to WS_DATA_SOURCE_NONE, and set the items, which are punctuated with comma. Set each item to the property WSNdata.

>       Format:(the property WSNuseIcon is True)
>         icon_filename,indent_level,1=open/0=close,the string\n...
>       Format:(the property WSNuseIcon is False)
>         indent_level,1=open/0=close,the string\n...

> If the icon is omitted in the case that the property WSNuseIcon is True, the value of WSNiconPixmap is used for the icon.

>     #include <WScom.h>
>     #include <WSCfunctionList.h>
>     #include <WSCbase.h>
>     //----------------------------------------------------------
>     //Function for the event procedure
>     //----------------------------------------------------------
>     #include <WSCtreeList.h>
>     extern WSCtreeList* newlist_001;
>     void btnep1(WSCbase* object){
>       //Delete all the items of the list.
>       newlist_001->delAll();
>       //Set the items of the list by the property
>       newlist_001->setProperty(WSNdataSource,WS_DATA_SOURCE_NONE);
>       newlist_001->setProperty(WSNdata,",0,1,item1\n,1,1,item2\n,2,1,item3");

>     static WSCfunctionRegister  op("btnep1",(void*)btnep1);

> ### Setting of the items from the file directly

> It is possible to set the items from the file directly. In such case at first,set WS_DATA_SOURCE_FILE to the property WSNdataSource, and set the file name to the property WSNdataSourceName as following program.

>     #include <WScom.h>
>     #include <WSCfunctionList.h>
>     #include <WSCbase.h>
>     //----------------------------------------------------------
>     //Function for the event procedure
>     //----------------------------------------------------------
>     #include <WSCtreeList.h>
>     extern WSCtreeList* newlist_001;
>     void btnep1(WSCbase* object){
>       //Delete all the items of the list
>       newlist_001->delAll();
>       //Set the items from file directly
>       newlist_001->setProperty(WSNdataSource,WS_DATA_SOURCE_FILE);
>       newlist_001->setProperty(WSNdataSourceName,"data.txt");
>     }
>     static WSCfunctionRegister  op("btnep1",(void*)btnep1);

>     //data.txt contains...
>     $(WSDIR)/sys/pixmaps/bi16.xpm,0,1,item1
>     1,1,item2
>     2,1,item3
>     3,1,item4
>     $(WSDIR)/sys/pixmaps/bi16.xpm,0,1,item5
>     1,1,item6
>     2,1,item7
>     3,1,item8

> ### Setting of the items from the other instance

> It is possible to set the items from the data source target property of the other instances. In such case, set WS_DATA_SOURCE_INSTANCE to the property WSNdataSource, and set the instance name to the property WSNdataSourceName. In the following example, a WSCtextField instance are specified to the property WSNdataSourceName and then it sets the string data of it to the list.

>     #include <WScom.h>
>     #include <WSCfunctionList.h>
>     #include <WSCbase.h>
>     //----------------------------------------------------------
>     //Function for the event procedure
>     //----------------------------------------------------------
>     #include <WSCtreeList.h>
>     extern WSCtreeList* newlist_001;
>     void btnep1(WSCbase* object){
>       //Delete all the items of the list
>       newlist_001->delAll();
>       //Set the items from the other instances
>       newlist_001->setProperty(WSNdataSource,WS_DATA_SOURCE_INSTANCE);
>       newlist_001->setProperty(WSNdataSourceName,"newtext_000");
>     }
>     static WSCfunctionRegister  op("btnep1",(void*)btnep1);

Document Release 3.70 for WideStudio ver 3.70, May 2004

WideStudio documents index | Table of contents

Copyright(C) WideStudio Development Team, 1999-2004 | Last modified: May 25, 2004