![]() | Programming Guide | WideStudio/MWT Index Table of contents |
树状列表
通过函数控制树状列表的数据显示
在树状列表 (WSCtreeList),或者WSClist 的列表类别为[树状列表]的列表中追加项目显示数据时, 同前面介绍的列表情况完全一样,使用addItem 函数指定追加的字符串和追加的位置。 省略追加位置时,将被追加到列表的末尾。同时,可以使用 setItemValue 函数设定列表项目的结构。 在引数中,将设定项目的位置,值别等指定于WS_INDENT_LEVEL,及阶层中。 完全不设定的情况下,将成为第0阶层,成为最初阶层。setItemValue(pos,WS_INDENT_LEVEL,level); pos =0,1,2,...,-1(最末尾) level =0VERB(top),1,2,3...下图是树状列表一览中追加项目的范例。
[树状列表一览]#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);在树状列表中,应该注意的是,在项目间完全没有任何关系,即各项目按指定状态进行显示。 因此,删掉最上层的项目,不会使其以下阶层的项目丢失。同时,跟前项之间的差为+1为止。 如果有+1以上差,将被自动订正为+1。通过属性设定详细列表的数据
项目数比较少时,能通过属性一次性设定项目内容。 首先,将WSNdataSource 属性设定为WS_DATA_SOURCE_NONE。 然后,用以下格式在WSNdata属性中设定数据。
数据格式:(属性 WSNuseIcon为True的情况)icon_filename,indent_level,1=open/0=close,项目字符串\n...数据格式:(属性 WSNuseIcon为 False 的情况)indent_level,1=open/0=close,项目字符串\n...如果省略图标,属性 WSNiconPixmap 中指定的图标将被作为图标使用。#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);通过文件设定树状列表数据
可以通过指定文件一次性设定项目内容。 首先,将WSNdataSource属性指定为 WS_DATA_SOURCE_FILE。 然后,在WSNdataSourceName属性中指定文件名。通过设定属性和程序实现动作。 下列是在程序中的设定的例子。#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通过Instance显示树状列表的数据
通过指定Instance名,从该Instance的数据源对象属性对项目进行总括设定。 首先,将WSNdataSource 属性设定为WS_DATA_SOURCE_INSTANCE。 然后,在WSNdataSourceName 属性中指定Instance名。 下列的例子中,指定了WSCtextField 的Instance(newtext_000)。 数据的形式,与文件指定的情况一样。被输入到newtext_000中的字符串在列表里将被显示。 通过builder的属性设定,程序的设定可以动作。 下列是在程序设定的例子。被输入区域的Instance newtext_000中所输入的字符串将作为树状列表的项目被显示。#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);
Copyright(C) WideStudio/MWT Development Team, 1999-2005 | Last modified: Jul 31, 2005 |