|
楼主 |
发表于 2014-3-7 14:18
|
显示全部楼层
本帖最后由 黑山上的鹰 于 2014-3-7 14:41 编辑
hwc2ycy 发表于 2014-3-7 09:14
添加按钮的代码,剩下的你可以试着写完。
谢谢,添加与删除按钮初步实现,再请教一下,从 listbox1按住Ctrl或Shift键多选移动到listbox2后,需要再次选择移动listbox1中内容追加到listbox2已有内容后,又怎么弄?谢谢
Private Sub CommandButton添加_Click() '〉
Dim i As Long
Dim j As Long
Dim k As Long
Dim arr() As Long
With ListBox1
If .ListCount > 0 Then
ReDim arr(1 To .ListCount)
For i = 0 To .ListCount - 1
If .Selected(i) Then
ListBox2.AddItem
ListBox2.List(k, 0) = .List(i, 0)
ListBox2.List(k, 1) = .List(i, 1)
k = k + 1
End If
Next i
For i = j To 1 Step -1
.RemoveItem arr(i)
Next i
End If
End With
If ListBox1.ListCount > 0 Then '删除已选项目
For i = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(i) = True Then
ListBox1.ListIndex = i
ListBox1.RemoveItem ListBox1.ListIndex
End If
Next i
End If
End Sub
Private Sub CommandButton删除_Click() '<
Dim i As Long
Dim j As Long
Dim k As Long
Dim arr() As Long
With ListBox2
If .ListCount > 0 Then
ReDim arr(1 To .ListCount)
For i = 0 To .ListCount - 1
If .Selected(i) Then
ListBox1.AddItem
ListBox1.List(k, 0) = .List(i, 0)
ListBox1.List(k, 1) = .List(i, 1)
k = k + 1
End If
Next i
For i = j To 1 Step -1
.RemoveItem arr(i)
Next i
End If
End With
If ListBox2.ListCount > 0 Then '删除已选项目
For i = ListBox2.ListCount - 1 To 0 Step -1
If ListBox2.Selected(i) = True Then
ListBox2.ListIndex = i
ListBox2.RemoveItem ListBox2.ListIndex
End If
Next i
End If
End Sub
|
|