The study notes PowerBuilder 8.5 Advanced Window Controls

1. list box control

List box control (ListBox), picture list box control (PictureListBox), drop-down list box control (DropDownListBox) and a drop-down list box control picture (DropDownPictureListBox).

 Role: to provide users a set of optional or visual options, run from the user to select one or more.

Common attributes category and description list box control:

Name list box control default prefix: lb_

Picture list box control named default prefix: plb_

Drop-down list box control named default prefix: ddlb_

Picture drop-down list box control named default prefix: ddplb_

 1.1 common attributes list box control, events and functions

1. list box control common properties

(1) Sorte properties: list entry specifies whether the list box is automatically sorted in ascending order.

(2) MultiSelect property: Specify whether users can select multiple list items, but can only be selected by clicking a mouse.

(3) ExtendedSelect attribute: Specifies whether users can simultaneously select a plurality of list items. Shift + mouse to select a number of consecutive, after Ctrl-click to select noncontiguous number, or pull out the rectangular box to select multiple items.

2. Common event list box control

(1) DoubleClicked events: double-click event

(2) SelectionChanged event: Triggered when a selected list of items in the list box.

3. commonly used functions list box control

(1) AddItem () function: add a new list item in the tail of the list items.

Format: AddItem (String item) Examples: ( "fifth item") lb_1.additem

(2) deleteitem (): Removes the specified list item

Format: deleteitem (Int index)

Where, index for the position you want to delete a numbered list item

For example: lb_1.deleteitem (3) // delete the third list item

(3) SelectedIndex (): Returns a list box, a list of required items index When more than one, returns the first index

The return value Integer. Examples: Integer li_no li_no = lb_1.SelectedIndex ()

(4) SelecteIndex (): returns the selected text in the list box control. When there are a plurality of list item is selected, the function returns the first selected text list item.

Usage above

(5) Text (): Returns the text specified in the list box options

Format: Text (Int index)

The return value is String

例:String sq

sq=lb_1.text(3)

(6) TotalItems (): Returns the total number of list items in the list box

The return value Integer

(7) TotalSelected (): Returns the total number of the selected list of items in the list box.

The return value Integer


(8) State () function: to determine whether a list box is selected (if highlighted).
Format:
State (Int index)
if the index parameter specifies a list item is selected (highlighted), the function returns 1; otherwise, it returns 0. If the index parameter is not specified by a list of valid entries, then the function returns -1. If any parameter is Null, the State () function returns Null.
Examples: Integer li_s
li_s lb_1.State = (. 3)
the IF THEN li_s. 1 =
...
the END the IF

(9) InsertItem () function: Insert a new entry in the list before the item indicated by the specified index.
Format:
InsertItem (Item String, Int index)
which, item to the list of items to be inserted, index for the index number.
For example, the third insert Computer:
lb_1.InsertItem ( "Computer",. 3)

(10) SelectItem () function.
Format 1: SelectItem (String item, Int index)

From the index at the beginning to find item, if found, then select the item and returns the index of the selected item.
For example:
Int R1
R1 = lb_1.selectitem ( "Book",. 1)

Format 2:
SelectItem (Int index)
selected index entry. If the index is 0, then uncheck the selection list box.
For example:
Int R1
R1 = lb_1.selectitem (. 3)

(11) SetState () function.
Format:
setState (Int index, boolean State)
set the index entry for highlighting or cancel highlighted. Wherein, state value is True, setting highlighted; State value is False, setting cancel highlighted. index = 0 means that all entries.
For example:
lb_1.setstate (2, TRUE) // second item highlighted
lb_1.setstate (0, FALSE) // cancel the highlight display all items lb_1

(12) FindItem () function: to find the specified string matches the specified index back a list of items in the item list.
Format:
FindItem (String text, Int index)
function returns the first to perform a successful index matching item. Which, text is the beginning of the string you want to find; index is an index to start searching before a list item. To find a list of all items, specify this parameter to 0.
For example, look at the list of items from the beginning of the second term beginning boo:
Int r
r = lb_1.finditem ( "boo", 1)

 

 2. The list view control, and tree view control

 1. list view control (ListView)

List view control is an advanced controls to express the data set using icons and text labels. Name the default prefix: lv_

1.1 List View control properties

Properties tab "ListView" controls have seven options page

 

Some unique attributes and description "General" page in the list view control

 

List View control of commonly used functions

Letter number

Features

return value

Parameter Description

Examples child

listviewname.
AddLargePicture
(picturename)

Add a big icon list icon

Add the return of big icons index on success, -1 on failure

listviewname: Name Listview control; picturename: Add the name of an icon

For the Listview control "lv_1" add a large icon pic.ico:

Integer index

index=lv_1.AddLargePicture("pic.ico")

listviewname.
DeleteLargePicture
(index)

Icon to remove a big icon list

Returns 1 if success, -1 on failure

listviewname:Listview控件的名称;index:大图标的索引

删除第1项大图标:

lv_1.DeleteLargePicture(1)

listviewname.
AddColumn
(label,lignment,

width)

在报告显示形式下添加一个指定的文本标签、对齐方式和宽度的特定栏目

成功时返回添加的栏目的索引,失败时返回-1

listviewname:Listview控件名称;label:添加的栏目的名称;alignment:添加的项目的对齐方式;width:添加的项目的宽度

在Listview控件的事件中,添加三个栏目:

This.AddColumn("名称",Left!,1000)

This.AddColumn("尺寸" ,Left!,400)

This.AddColumn("日期",Left!,300)

listviewname.
Sort(sorttype,
{ column })

对Listview控件中的项目进行排序

成功时返回1,失败时返回-1

listviewname:Listview控件名称;sorttype:排序方式;column:指定排序的栏目

对第2列按升序排序:

lv_1.SetRedraw(FALSE)

lv_1.Sort(Ascending! , 2)

lv_1.SetRedraw(TRUE)

listviewname.
TotalItems()

读取全部项目数

成功时返回项目数,失败时返回-1

 

读取“lv_1”项目数:

Integer Total

Total = lv_1.TotalItems()

listviewname.
TotalColumns()

读取全部栏目数

成功时返回栏目数,失败时返回-1

 

读取“lv_1”栏目数:

Integer Total

Total = lv_1.TotalColumns()

listviewname.
TotalSelected()

读取选中的项目数

成功时返回项目数,失败时返回-1

 

读取“lv_1”选中的项目数:

Integer Selected

Selected=lv_1.TotalSelected()

listviewname.
SelectedIndex()

读取当前选中项目的索引号

成功时返回选中项目的索引号,没有选中或失败时返回-1

 

读取“lv_1”选中的项目的索引号:

Integer li_Index

li_Index=lv_1.SelectedIndex()

listviewname.
AddItemlabel,

picindex)

添加项目

成功时返回添加项目的索引,失败时返回-1

label:添加的项目的名称;picindex:图片索引号

添加项目:

lv_1.AddItem("数学系",3)

listviewname.InsertItem(index,label,picindex)

插入项目

成功时返回插入项目的索引,失败时返回-1

index:要插入的项目索引号;label:添加的项目的名称;picindex:图片索引号

插入项目:

lv_1.InsertItem(2, "CCTV",4)

listviewname.DeleteItem(index)

删除项目

成功时返回1,失败时返回-1

index:要删除的项目索引号

删除项目:

lv_1.DeleteItem(3)

listviewname.
SetItem(index,
column,label)

设置指定项、指定栏目的标签

成功时返回1,失败时返回-1

index:要设置的项目索引号;column:栏目号;label:要设置的项目的标签

设置指定项、指定栏目的标签

lv_1.SetItem(1,1,"刘明")

lv_1.SetItem(1,2,"男")

lv_1.SetItem(1,3,"23")

lv_1.SetItem(1,4,"南京师大")

listviewname.

GetItem index,

column,label)

读取指定索引、指定栏目的标签

成功时返回1,失败时返回-1

index:要读取的项目索引号;column:栏目号;label:读取的项目的标签

读取第3个项目的第2栏的内容:

String s1

Lv_1.GetItem(3,2,s1)

 

 

 ListView控件的常用事件

 2.树状视图控件

 树状视图控件(TreeView)是以树图形式组织项目的,具有直观和易于管理的特点。命名默认前缀:tv_

1.树状视图控件的常用属性

(1)“HasButtons”属性:指定是否在父节点列表项前显示“+”和“-”按钮,取值为True或False。用户单击“+”按钮时将扩展列表项,单击“-”按钮时将折叠列表项。
(2)“HasLines”属性:指定是否用连线将列表项连接起来,取值为True或False。
(3)“Indent”属性:值为Integer类型,指定下层节点(列表项)的缩进宽度,以PBU为单位。可以使用负值,此时节点被缩进到该控件的边界外边。
(4)“LinesAtRoot”属性:指定是否使用连线连接所有根节点,取值为True或False。
(5)“SortType”属性:取值为枚举类型,指定列表项按标题名排序的方式。有效取值为“Ascending!”“Descending!”“UserDefined!”“Unsorted!”
(6)PictureName[ ]:String型数组,表示该控件使用的图像文件名。可以在创建树状视图时,通过其“Picture”属性页加入这些图像文件。

2.树状视图控件的常用事件有以下九种。
(1)“SelectionChanged”事件:在用户选择新的选项后触发。该事件是树状视图控件比较常用的事件。
(2)“SelectionChanging”事件:当用户选择新的选项时触发。该事件返回1时阻止用户改变当前选项,返回0时允许用户改变当前选项。
(3)“ItemCollapsed”事件:在某个列表项被折叠后触发。
(4)“ItemCollapsing”事件:在某个列表项要被折叠时触发。该事件返回1时阻止折叠,返回0时完成折叠。
(5)“ItemExpanded”事件:在某个列表项被展开后触发。
(6)“ItemExpanding”事件:在某个列表项要被展开时触发。该事件返回1时阻止展开,返回0时完成展开。
(7)“ItemPopulate”事件:当第1次展开某列表项时触发。该事件返回1时阻止展开,返回0时完成展开。
(8)“DoubleClicked”事件:双击鼠标时触发。
(9)“RightClicked”事件:右击鼠标时触发。

 

 

3.树状视图的常用函数

(1)AddPicture()函数。
格式:
AddPicture(String picturename)
在图像列表中增加图片文件,返回值为新加入的图片文件索引号。
(2)CollapseItem()函数。
格式:
CollapseItem(Long itemhandle)
折叠指定的列表项(节点)。其中,itemhandle为要折叠的列表项的句柄(一个长整数,每个节点都有一个唯一代表该节点的句柄)。成功时返回1,失败时返回-1。
(3)ExpandAll()函数。
格式:
ExpandAll(Long itemhandle)
展开指定列表项(节点)的所有各级子项(子节点)。itemhandle为要展开各级子项的列表项的句柄。
(4)ExpandItem()函数。
格式:
ExpandItem(Long itemhandle)
展开指定的列表项(节点)。itemhandle为要展开列表项的句柄。
ExpandItem()函数只展开指定的列表项,而不展开该列表项下的各级子列表项。
(5)FindItem()函数。
格式:
FindItem(navigationcode,itemhandle)
根据列表项位置返回指定列表项的句柄,失败时返回-1。其中,itemhandle为开始查找的列表项的句柄,Long型;navigationcode为要查找的节点,枚举类型,取值如下。
① RootTreeItem!:根节点。
② NextTreeItem!:与itemhandle列表项同一个父节点中同一层的下一个列表项。
③ PreviousTreeItem!:与itemhandle列表项同一个父节点中同一层的前一个列表项。
④ ParentTreeItem!:itemhandle列表项的父节点。
⑤ ChildTreeItem!:itemhandle节点的第一个子列表项。
⑥ CurrentTreeItem!:当前所选列表项。
例如,得到树状视图控件中当前所选项的句柄:
Long tv_curt
tv_curt=tv_1.FindItem(CurrentTreeItem!, 0)
例如,如果希望展开树状视图控件中的所有列表项,则以根节点的句柄为参数调用ExpandAll()函数:
Long tv_rt //查找根节点的句柄
tv_rt = tv_1.FindItem(roottreeitem!,0) //展开所有节点
tv_1. ExpandAll(tv_rt)
(6)GetItem()函数。
格式:
GetItem(itemhandle,item)
得到指定句柄的完整列表项。其中,itemhandle为要得到完整信息的列表项的句柄,为Long型;item为TreeViewItem类型的变量,用于保存itemhandle参数指定列表项的完整信息。
使用GetItem()函数可以得到指定列表项的完整信息,如标题label、句柄itemhandle、使用的图片索引pictureindex等。
(7)InsertItemLast()函数。
格式:
InsertItemLast(handleparent,label,pictureindex)
在末尾加入新节点。其中,handleparent为指定要插入列表项父节点的句柄;label为新插入列表项的标题,即显示在树状视图控件中的文字;pictureindex为新插入列表项标题前显示的图片的索引号。返回值为Long型。函数执行成功时返回新插入列表项的句柄;发生错误时返回-1。
例如,下面的代码在当前列表项后面加入一个列表项“计算机系”,新加入列表项与当前列表项位于同一个层次上(有相同父节点):

Long tv_ct, tv_parent //首先求当前列表项的句柄
tv_ct = tv_1.FindItem(CurrentTreeItem!,0) //再求当前列表项父节点的句柄
tv_parent = tv_1.FindItem(ParentTreeItem!,tv_ct) //加入新列表项
tv_1.InsertItemLast(tv_parent,"计算机系",2)
(8)InsertItem()函数。
格式:
InsertItem(handleparent,handleafter,label,pictureindex)
插入新节点。其中,handleparent指定要插入列表项父节点的句柄;handleafter指定在同一层中句柄为handleafter的项后面插入新项;label为新插入列表项的标题,即显示在树状视图控件中的文字;pictureindex为新插入列表项标题前显示的图片的索引号。返回值为Long型。函数执行成功时返回新插入列表项的句柄,发生错误时返回-1。
例如,下面的代码在当前列表项后面插入一个列表项,新插入列表项与当前列表项位于同一个层次上:
Long tv_ct, tv_parent //得到当前列表项的句柄
tv_ct = tv_1.FindItem(currenttreeitem!,0) //得到当前列表项父列表项的句柄
tv_parent = tv_1.FindItem(parenttreeitem!,tv_ct) //插入新列表项
tv_1.InsertItem(tv_parent,tv_ct,"计算机系",2)
(9)InsertItemFirst()函数。
格式:
InsertItemFirst(handleparent,label,pictureindex)
插入新节点。其中,handleparent指定要插入列表项父节点的句柄;label为新插入列表项的标题,即显示在树状视图控件中的文字;pictureindex为新插入列表项标题前显示的图片的索引号。返回值为Long型。函数执行成功时返回新插入列表项的句柄,发生错误时返回-1。
(10)SelectItem()函数。
格式:
SelectItem(Long itemhandle)
选中指定的列表项(高亮显示该列表项),使其成为当前列表项。
(11)SetItem()函数。
格式:
SetItem(itemhandle, item)
设置指定列表项的数据。其中,itemhandle为要设置列表项数据节点的句柄;item为TreeViewItem对象指定新的数据值。
例如,要将当前列表节点的标签“计算机系”改为“南京师大计算机系”:
Long tv_ct
treeviewitem im //得到当前列表项的句柄
tv_ct = tv_1.FindItem(currenttreeitem!,0)
GetItem(tv_ct, im)
Im.label="南京师大计算机系"
SetItem(tv_ct,im)
(12)Sort()函数。
格式:
Sort(itemhandle,sorttype)
节点排序。其中,itemhandle指定要对其子列表项排序的列表项的句柄;sorttype指定排序方式,取值为Ascending!、Descending!和UserDefined!。
Sort()函数只对指定列表项下面第一层子项进行排序。
(13)SortAll()函数。
格式:
SortAll(itemhandle, sorttype)


通常在窗口的“Open”事件中为“TreeView”加上根节点,在“TreeView”控件的“SelectionChanged”事件或其他事件中编写加入子节点的代码。
当然也可以在窗口的“Open”事件中生成“TreeView”的全部子节点。

 

Guess you like

Origin www.cnblogs.com/Bokeyan/p/11364095.html