VB 如何把乙個listbox作為引數傳遞

2021-07-25 02:50:03 字數 1901 閱讀 2243

方法一:

listbox2.items.clear()

for i = 0 to listbox1.items.count - 1

listbox2.items.add(listbox1.items(i))

next

這樣就將listbox1的列表項移動到另乙個listbox2中了

這是利用for迴圈;提取第乙個列表框listbox1中的所有列表項,再全部載入到另乙個listbox2

方法二:更好,但是還沒完全看懂,網上搜了一下,都是有關vb.net的程式設計

public class form1

'listbox之間專案拖動示例,左鍵移動,右鍵複製

private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load

listbox2.allowdrop = true

end sub

private sub listbox1_mousedown(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles listbox1.mousedown

dim dragindex = listbox1.indexfrompoint(e.x, e.y)

if dragindex <> listbox.nomatches then

listbox1.selectedindex = dragindex

if e.button = windows.forms.mousebuttons.left then

dodragdrop(listbox1.items(dragindex), dragdropeffects.move)

elseif e.button = windows.forms.mousebuttons.right then

dodragdrop(listbox1.items(dragindex), dragdropeffects.copy)

end if

end if

end sub

private sub listbox2_dragenter(byval sender as object, byval e as system.windows.forms.drageventargs) handles listbox2.dragenter

e.effect = e.allowedeffect

end sub

private sub listbox2_dragdrop(byval sender as object, byval e as system.windows.forms.drageventargs) handles listbox2.dragdrop

dim item as object = ctype(e.data.getdata(gettype(system.string)), system.object)

dim item2 as integer = listbox2.indexfrompoint(listbox2.pointtoclient(new point(e.x, e.y)))

if item2 = -1 then

listbox2.items.add(item)

else

listbox2.items.insert(item2, item)

end if

if e.allowedeffect = dragdropeffects.move then

listbox1.items.remove(item)

end if

end sub

end class

還有乙個vb問題

這是為什麼啊?望高人指點啊.private sub form load dim machine as string dim machine decode as string dim txtsql as string dim mrc as adodb.recordset dim msgtext as ...

建立的第乙個Listbox 控制項

using system using system.collections.generic using system.linq using system.web using system.web.ui using system.web.ui.webcontrols 修改後 using system ...

VB 乙個正則提取功能

引用 microfoft vbscript regular expressions 5.5 乙個正則提取功能 public function reggetstr three byval mystring as string,byval patreg as string as string dim o...