提供
单item函数:
cmddel_click
cmdadd_click
多item函数:
cmddelall_click
cmdaddall_click
———————————————————————————————————————
option explicit
author:nyb
time:2002-04-05
传入list1,list2,然后我们可以对list1,和list2中的item进行处理.
*all areas of code where modifications are necessary
*to integrate this object with a project are documented
with comments denoted by note:.
*to locate these comments,search for ‘*note::.
****************************************************************************************
public sub cmddelall_click(list1 as listbox, list2 as listbox) <<
*purpose: delete all list2.item
*accept: list1 没有用,list2处理对象
for i = (list2.listcount – 1) to 0 step -1
list2.removeitem i
next i
end sub
public sub cmdadd2to1_click(list1 as listbox, list2 as listbox, list3 as listbox) >>
*purpose: all item of list1 and list2 are inputed to list3
*accept: list1,list2
for i = 0 to (list1.listcount – 1)
list3.additem list1.list(i)
next i
for i = 0 to (list2.listcount – 1)
list3.additem list2.list(i)
next i
end sub
public sub cmdaddall_click(list1 as listbox, list2 as listbox, index as integer) >>
*purpose: add all item of list1 inputed to list2.if item had been there, it wont be inputed
*accept: list1,list2
if list2.listcount = 0 then
for i = 0 to (list1.listcount – 1)
list2.additem list1.list(i)
next i
else
for i = 0 to (list1.listcount – 1)
flag = checkselected(list1, list2, list1.list(i))
if flag = "notbe" then list2.additem list1.list(i)
next i
end if
end sub
public sub cmddel_click(list1 as listbox, list2 as listbox) <—
*purpose: the selected items of list2 are cleared
*accept: list1 没有用,list2处理对象
dim i as integer
if list2.selcount > 0 then
for i = (list2.listcount – 1) to 0 step -1
if list2.selected(i) = true then list2.removeitem i
next i
end if
end sub
public sub cmdadd_click(list1 as listbox, list2 as listbox, index as integer) —>
*purpose: the selected items of list1 is inputed into list2
list2为空,list2又可以多选,那么items selected in list1 are inputed to list2
list2不为空,list2又可以多选,那么先检查item是否在list2中,如果在,那么就不添入list2
list2设为单选,那么list2只添加list1中的的第一选中项
*accept: list1 选中的项目,list2为要加入的listbox
dim i as integer
dim flag as string
if index > 0 then
if list2.listcount >= 1 then
if index = 2 then
if list2.listcount >= 2 then
if list1.multiselect = 0 then
msgbox "只能选定两期对比!", vbexclamation, "操作提示!"
exit sub
end if
end if
end if
end if
end if
if list2.listcount = 0 and list2.multiselect = 2 then
for i = 0 to (list1.listcount – 1)
if list1.selected(i) = true then list2.additem list1.list(i)
next i
elseif list2.listcount > 0 and list2.multiselect = 2 then
for i = 0 to (list1.listcount – 1)
flag = checkselected(list1, list2, list1.list(i))
if list1.selected(i) = true and flag = "notbe" then list2.additem list1.list(i)
next i
elseif list2.multiselect = 0 then
call cmddelall_click(list1, list2)
for i = 0 to (list1.listcount – 1)
if list1.selected(i) = true then list2.additem list1.list(i)
next i
end if
call clearselect(list1)
end sub
private function checkselected(list1 as listbox, list2 as listbox, cityitem as string) as string
*purpose: 检查item是否已经被添加,已添加则checkselected = "be"
*accept: list1 选中的项目,list2为要加入的listbox,cityitem为list1 中一个被选中的项目
*feedback: checkselected , "be" 表示这个item在list2中存在
for i = (list2.listcount – 1) to 0 step -1
if cityitem = list2.list(i) then
checkselected = "be"
exit for
else: checkselected = "notbe"
end if
next i
end function
private sub clearselect(list1)
*purpose: clear list1s selected
*accept: list1 ,the list box to clear selected
for i = 0 to list1.listcount – 1
if list1.selected(i) = true then
list1.selected(i) = false
end if
next i
end sub
