在做數(shù)據(jù)庫程序時,通常會要求用戶將數(shù)據(jù)從一個列表框移動到別一個列表框中。下面的子程序可以讓你輕松實(shí)現(xiàn)這一功能。同時還提供參數(shù),指定操作是移動數(shù)據(jù)(不保留原數(shù)據(jù)),還是拷貝數(shù)據(jù)(保留數(shù)據(jù)的副本在原列表框或組合框中);并且還可以選擇是全部移動或拷貝數(shù)據(jù),還是只移動或拷貝用戶選定的部分。
參數(shù) 值 說明
fromctl 源列表框或組合框名 源列表框或組合框
toctl 目的列表框或組合框名 目的列表框或組合框
strmode 可選參數(shù),默認(rèn)情況下只拷貝
選中的項(xiàng)目
- 移動選中的項(xiàng)目
all 拷貝所有的項(xiàng)目,不需選中
-all 移動所有的項(xiàng)目,不需選中
源程序如下:
public sub copycombolist(fromctl as control, toctl as control, optional
strmode as string)
on error resume next
dim intn as integer
screen.mousepointer = vbhourglass
if strmode <> "" then
strmode = ucase(strmode)
end if
with fromctl
if typename(fromctl) = "listbox" then
for intn = .listcount - 1 to 0 step -1
if .selected(intn) or instr(strmode, "all") then
toctl.additem .list(intn)
toctl.itemdata(toctl.newindex) = .itemdata(intn)
if instr(strmode, "-") = 1 then
.removeitem (intn)
end if
next
else
for intn = .listcount - 1 to 0 step -1
toctl.additem .list(intn)
toctl.itemdata(toctl.newindex) = .itemdata(intn)
if instr(strmode, "-") = 1 then
.removeitem (intn)
next
end if
end with
screen.mousepointer = vbdefault
end sub
參數(shù) 值 說明
fromctl 源列表框或組合框名 源列表框或組合框
toctl 目的列表框或組合框名 目的列表框或組合框
strmode 可選參數(shù),默認(rèn)情況下只拷貝
選中的項(xiàng)目
- 移動選中的項(xiàng)目
all 拷貝所有的項(xiàng)目,不需選中
-all 移動所有的項(xiàng)目,不需選中
源程序如下:
public sub copycombolist(fromctl as control, toctl as control, optional
strmode as string)
on error resume next
dim intn as integer
screen.mousepointer = vbhourglass
if strmode <> "" then
strmode = ucase(strmode)
end if
with fromctl
if typename(fromctl) = "listbox" then
for intn = .listcount - 1 to 0 step -1
if .selected(intn) or instr(strmode, "all") then
toctl.additem .list(intn)
toctl.itemdata(toctl.newindex) = .itemdata(intn)
if instr(strmode, "-") = 1 then
.removeitem (intn)
end if
next
else
for intn = .listcount - 1 to 0 step -1
toctl.additem .list(intn)
toctl.itemdata(toctl.newindex) = .itemdata(intn)
if instr(strmode, "-") = 1 then
.removeitem (intn)
next
end if
end with
screen.mousepointer = vbdefault
end sub

